#include #include #include #include #include typedef struct itmlst { short len; short code; char *buff; int *rlen; } Itmlst; Itmlst nulllist[] = { {0,0,0,0} }; #define INIT_ITEM(i,l,c,b,r) {\ i.len = l;\ i.code = c;\ i.buff = b;\ i.rlen = r;\ } void main (void) { /* * "Ruslan R. Laishev" */ char from [ ] = "MX%\"Ruslan R. Laishev\"%laishev@host1.petrobank.spb.su"; char to [ ] = "laishev"; char subj [ ] = "Test of mail$"; char body [ ] = "Hello World !\r\nThis is a test!\r\n/@RRL"; nntp_post_bymail ( from,sizeof(from)-1, to,sizeof(to)-1, subj,sizeof(subj)-1, body,sizeof(body)-1); } #define MAXREC 5 int nntp_post_bymail ( char *from, int fromsz, char *to, int tosz, char *subj, int subjsz, char *body, int bodysz ) { long status; int context = 0; int sz,i; char *cp0,*cp1; Itmlst body_list [2]; Itmlst attr_list [4]; Itmlst addr_list [2]; Itmlst send_list [2]; INIT_ITEM (attr_list[0],fromsz,MAIL$_SEND_FROM_LINE,from,0); INIT_ITEM (attr_list[1],subjsz,MAIL$_SEND_SUBJECT,subj,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); printf("\nFrom:%.*s",fromsz,from); printf("\nTo:%.*s",tosz,to); status = mail$send_begin(&context, nulllist, nulllist); if (! (status & 1) ) lib$signal(status); /* * Make up "FROM:" field of messages */ status = mail$send_add_attribute(&context,attr_list,nulllist); if (! (status & 1) ) lib$signal(status); /* * Warning ! Don't change order of add_attribute and add_address */ status = mail$send_add_address(&context,addr_list,nulllist); if (! (status & 1) ) lib$signal(status); cp0 = body; while ( cp1 = strpbrk (cp0,"\r\n") ) { sz = cp1 - cp0; INIT_ITEM (body_list[0],sz,MAIL$_SEND_RECORD,cp0,&sz); INIT_ITEM (body_list[1],0,0,"",0); status = mail$send_add_bodypart(&context,body_list,nulllist); if (! (status & 1) ) lib$signal(status); cp0 = cp1 + strspn(cp1,"\r\n"); } if ( 0 < (sz = bodysz - (cp0 - body)) ) { INIT_ITEM (body_list[0],sz,MAIL$_SEND_RECORD,cp0,&sz); INIT_ITEM (body_list[1],0,0,"",0); status = mail$send_add_bodypart(&context,body_list,nulllist); if (! (status & 1) ) lib$signal(status); } status = mail$send_message(&context,nulllist,nulllist); if (! (status & 1) ) lib$signal(status); status = mail$send_end(&context,nulllist,nulllist); if (! (status & 1) ) lib$signal(status); return status; }