#include #include #include #include #include #include #include #include "nntp.h" #define INIT_SDESC(dsc, len, ptr) {(dsc).dsc$b_dtype = DSC$K_DTYPE_T;\ (dsc).dsc$b_class = DSC$K_CLASS_S; (dsc).dsc$w_length = (len);\ (dsc).dsc$a_pointer = (ptr);} int strelem ( char *dst, char *src, int src_len, char *sep_set, int elem ) { char *cp0,*cp1; int pos; int new_len = 0; cp0 = cp1 = src; *(src+src_len) = 0; for ( ; elem >= 0; elem--) { cp0 = cp1; /* * Search for start of element; */ if ( src_len <= (pos = strspn (cp0,sep_set)) ) return 0; if (*(cp0 +=pos) == 0) return 0; /* * Search for end of element; */ if ( NULL == (cp1 = strpbrk(cp0,sep_set)) ) cp1 = src+src_len; } /* * Compute length of element and coping it to *dst; */ if ( new_len = cp1-cp0 ) { memcpy(dst,cp0,new_len); *(dst+new_len) = 0; } return (new_len); } /* * */ typedef struct itmlst { short len; short code; char *buff; int *rlen; } Itmlst; #define INIT_ITEM(i,l,c,b,r) {\ i.len = l;\ i.code = c;\ i.buff = b;\ i.rlen = r;\ } #define MAXREC 250 int smail ( char *to, int tosz, char *subj, int subjsz, char *body, int bodysz, char *from, int fromsz ) { long status; int context = 0; int sz,i; char *cp0,*cp1; Itmlst body_list [2]; Itmlst attr_list [3]; Itmlst addr_list [2]; Itmlst nulllist[] = { {0,0,0,0} }; INIT_ITEM (attr_list[0],subjsz,MAIL$_SEND_SUBJECT,subj,0); INIT_ITEM (attr_list[1],fromsz,MAIL$_SEND_FROM_LINE,from,0); INIT_ITEM (attr_list[2],0,0,"",0); INIT_ITEM (addr_list[0],tosz,MAIL$_SEND_USERNAME,to,0); INIT_ITEM (addr_list[1],0,0,"",0); status = mail$send_begin(&context, nulllist, nulllist); if (! (status & 1) ) { perror("send_mail:mail$send_begin"); return -1; } /* * */ status = mail$send_add_attribute(&context,attr_list,nulllist); if (! (status & 1) ) { perror("send_mail:mail$send_add_attribute"); return -1; } /* * Warning ! Don't change order of add_attribute and add_address */ status = mail$send_add_address(&context,addr_list,nulllist); if (! (status & 1) ) { perror("send_mail:mail$add_address"); return -1; } cp0 = body; while ( cp1 = strpbrk (cp0,"\r\n") ) { sz = cp1 - cp0; INIT_ITEM (body_list[0],sz,MAIL$_SEND_RECORD,cp0,0); INIT_ITEM (body_list[1],0,0,"",0); sz = min(MAXREC,sz); status = mail$send_add_bodypart(&context,body_list,nulllist); if (! (status & 1) ) { perror("send_mail:mail$send_add_bodypart"); return -1; } cp0 = cp0+ sz + strspn(cp1,"\r\n"); } if ( 0 < (sz = bodysz - (cp0 - body)) ) { INIT_ITEM (body_list[0],sz,MAIL$_SEND_RECORD,cp0,0); INIT_ITEM (body_list[1],0,0,"",0); status = mail$send_add_bodypart(&context,body_list,nulllist); if (! (status & 1) ) { perror("send_mail:mail$send_add_bodypart"); return -1; } } status = mail$send_message(&context,nulllist,nulllist); if (! (status & 1) ) { perror("send_mail:mail$send_message"); return -1; } status = mail$send_end(&context,nulllist,nulllist); if (! (status & 1) ) { perror("send_mail:mail$send_end"); return -1; } return 0; } void main (void) { char to[] = "MX%\"Laishev@SMTP.DeltaTel.RU\""; char from[] = "laishev@SMTP.DeltaTel.RU"; char subj[2048]; char body[] = "Hello World !"; int i; strcpy (subj,"Test of send mail\r\nNewsgroups: test.test\r\n"); for (i = 0; i < 32;i++) strcat (subj,"-----------------------------------\r\n"); printf("len %d",strlen(subj)); smail (to,sizeof(to)-1, subj,strlen(subj), body,sizeof(body)-1, from,sizeof(from)-1); }