#include #include #include #include #include #define __NEW_STARLET 1 #include #include #include "mxdef.h" #include "mxmacros.h" #include "mxin_msg.h" extern void * SITE_IN_CLD; $DESCRIPTOR (p1_dsc ,"MSGFILE"); $DESCRIPTOR (p2_dsc ,"ADDRFILE"); $DESCRIPTOR (p3_dsc ,"SENDER"); $DESCRIPTOR (pref_dsc,"SITE_IN "); $DESCRIPTOR (nul_dsc, ""); $DESCRIPTOR (sep_dsc, ", "); $DESCRIPTOR (at_dsc, "@"); $DESCRIPTOR (sps_dsc, " "); $DESCRIPTOR (sep2_dsc, " \t"); $DESCRIPTOR (mxsrc_dsc, "SRC_INFO"); $DESCRIPTOR (mxhdr_dsc, "HDR_INFO"); $DESCRIPTOR (mxmsg_dsc, "MSG_TEXT"); int mx_site_in ( struct dsc$descriptor *msg, struct dsc$descriptor *adr, struct dsc$descriptor *snd) { int status,maxmsgsize = 0,unit = 0,unit2; struct dsc$descriptor str,lcl,dom,to,strhdr; MX_RCPT *rcpt; MX_TXT *txt; MX_QCTX *qctx; $MX_QENT (qent); $MX_QUE (rtq); $MX_QUE (hdr); $MX_QUE (outhdr); $MX_ENVL (envl); /* ** Open a context to the MX's FLQ */ if ( !(1 & (status = flq_open (FLQ__FULL, &qctx))) ) lib$stop(MXIN__QOPENERR, 0,status); /* ** Get a maximal message size (MX_FLQ_MAX_ENTRY_SIZE) */ if ( !(1 & (status = flq_get_maxsize (&qctx, &maxmsgsize))) ) lib$stop(MXIN__QMAXSZERR, 0,status); /* ** Format Sender address */ if ( !(1 & (status = mx_fmt_lcl_addr(MX__FMT_ENVFROM | FMT_M_LOWERCASE,snd,snd))) ) return status; /* ** Process recipients' address file */ if ( !(1 & (status = mx_file_open (MX__FILE_READ,adr, &unit))) ) lib$stop(MXIN__RCPTFILERR,1,adr,status); INIT_DDESC(str); INIT_DDESC(lcl); INIT_DDESC(dom); INIT_DDESC(to); while ( 1 & (status = mx_file_read (unit, &str)) ) { /* ** Reading file, parse & check recipients address */ if ( !(1 & (status = parse821 (&str,&rtq,&lcl,&dom))) ) lib$stop(MXIN__INVRCPTADDR, 2, envl.envl$l_rcptcount+1, &str); /* ** Allocate memory & store recipient address string "recipient context" */ if ( !(1 & (status = mem_getrcpt (&rcpt,str.dsc$w_length))) ) lib$stop(MXIN__ALLOCERR,0,status); memcpy(rcpt->rcpt$a_addr->txt$t_text,str.dsc$a_pointer,str.dsc$w_length); rcpt->rcpt$a_addr->txt$w_len = str.dsc$w_length; printf("%.*s\n",rcpt->rcpt$a_addr->txt$w_len,rcpt->rcpt$a_addr->txt$t_text); /* ** Insert new recipient into the recipients list */ _INSQUE(rcpt,envl.envl$r_rcptque.que$a_tail); envl.envl$l_rcptcount++; if ( (to.dsc$w_length + str.dsc$w_length + 2) < 1024 ) status = str$concat(&to,&to,to.dsc$w_length?&sep_dsc:&nul_dsc, &lcl,&at_dsc,&dom); } mx_file_close (unit); if ( !(1 & status) && (status != RMS$_EOF) ) lib$stop(MXIN__RCPTFILERR,1,adr,status); else if ( !envl.envl$l_rcptcount ) lib$stop(MXIN__NORECIPIENTS,0); /* ** Process message file: open, read message header part info the ** memory... */ if ( !(1 & (status = mx_file_open (MX__FILE_READ,msg, &unit))) ) lib$stop(MXIN__RCPTFILERR,1,msg,status); INIT_DDESC(strhdr); status = mx_file_read (unit, &str); printf("-----------------\n"); do { str$trim(&str,&str); if ( (*str.dsc$a_pointer == ' ') || (*str.dsc$a_pointer == '\t') ) { status = max(1,str$find_first_not_in_set (&str,&sep2_dsc)); str$right (&str,&str,&status); str$concat(&strhdr,&strhdr,&sps_dsc,&str); } else if ( !strhdr.dsc$w_length ) ots$scopy_dxdx(&str,&strhdr); else { txt = mem_gettxt (strhdr.dsc$w_length,strhdr.dsc$a_pointer); _INSQUE(txt,hdr.que$a_tail); str$free1_dx(&strhdr); ots$scopy_dxdx(&str,&strhdr); } } while ( 1 & (status = mx_file_read (unit, &str)) && str.dsc$w_length ); if ( !(1 & status) && (status != RMS$_EOF) ) lib$stop(MXIN__MTXTFILERR,1,msg,status); /* ** Parse the loaded header part, assign to every record a field code */ status = parse_hdrs (&hdr, &outhdr); for (txt = outhdr.que$a_head; &outhdr != txt; txt = txt->txt$a_head) { printf("code = %8.8u : %.*s\n",txt->txt$w_code,txt->txt$w_len,txt->txt$t_text); switch (txt->txt$w_code) { case MX_K_HDR_FROM: envl.envl$v_fromadr = 1; envl.envl$a_fromadr = txt; break; case MX_K_HDR_DATE: break; case MX_K_HDR_TO: break; case MX_K_HDR_RECEIVED: envl.envl$v_rcvdfrom = 1; envl.envl$a_rcvdfrom = txt; break; case MX_K_HDR_SENDER: envl.envl$v_orgsender = 1; envl.envl$a_orgsender = txt; break; case MX_K_HDR_MESSAGE_ID: break; } } /* ** Prepare new MX Entry */ qent.qent$l_status = FLQ_K_STINP; qent.qent$v_lock = 1; qent.qent$l_dstprc = FLQ_K_MX_ROUTER; qent.qent$l_origin = MX_K_ORG_SITE; qent.qent$w_orgadr = snd->dsc$w_length; memcpy(qent.qent$t_orgadr,snd->dsc$a_pointer,snd->dsc$w_length); if ( !(1 & (status = flq_add(&qctx,&qent))) ) lib$stop(MXIN__MSGENQERR,0,status); envl.envl$envl_fldflags |= ENVL$M_ORIGIN | ENVL$M_FROMADR; envl.envl$l_origin = MX_K_ORG_SITE; envl.envl$a_orgsender = mem_gettxt (qent.qent$w_orgadr,qent.qent$t_orgadr); if ( (1 & (status = write_envelope (&qctx,&qent,&mxsrc_dsc,&envl))) && (1 & (status = write_hdrs (&qctx,&qent,&mxhdr_dsc,&outhdr))) && (1 & (status = flq_make_fspec (qent.qent$l_entnum,&mxmsg_dsc,&str))) && (1 & (status = mx_file_open (MX__FILE_WRITE,&str, &unit2))) ) while( (1 & (status = mx_file_read(unit,&str))) && (1 & (status = mx_file_write(unit2,&str))) ) qent.qent$l_size += str.dsc$w_length; mx_file_close(unit); if ( !(1 & status ) && (status != RMS$_EOF) ) { qent.qent$l_status = FLQ_K_STCAN; status = flq_update (&qctx,&qent); mx_file_close(unit2,1); lib$stop(MXIN__WRTMSGERR, 0,status); } mx_file_close(unit2); /* ** */ qent.qent$l_status = FLQ_K_STRDY; if ( !(1 & (status = flq_update (&qctx,&qent))) ) lib$stop(MXIN__MSGENQERR,0,status); lib$signal(MXIN__MSGENQUEUED,1,qent.qent$l_entnum); return SS$_NORMAL; } int main (void) { int status; struct dsc$descriptor cmd,msg,adr,snd; INIT_DDESC(cmd); if ( !(1 & (status = lib$get_foreign (&cmd))) ) return status; if ( !(1 & (status = str$prefix (&cmd, &pref_dsc))) || !(1 & (status = cli$dcl_parse (&cmd,&SITE_IN_CLD,0,0))) ) return status; INIT_DDESC(msg); INIT_DDESC(adr); INIT_DDESC(snd); if ( !(1 & (status = cli$get_value (&p1_dsc,&msg))) ) return status; if ( !(1 & (status = cli$get_value (&p2_dsc,&adr))) ) return status; if ( !(1 & (status = cli$get_value (&p3_dsc,&snd))) ) return status; else if ( snd.dsc$a_pointer == '"' ) { snd.dsc$a_pointer++; snd.dsc$w_length -=2; } return(status = mx_site_in(&msg,&adr,&snd)); }