[Raw Msg Headers][Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Submitting messages from perl
Ryan, I'm sorry, if I accidentally flamed you as a spammer.
>From my point of view you were very like to one.
BTW, I still think that all "direct marketing" is an evil,
as is any active advertisment, with only a few exceptions.
Trying to compensate this mistake, I wrote wrapper program in C
to be called from perl. The program "mdist" expects on stdin standard
mailbox with multiple messages, each starting from the symbols "From "
in the beginning of line. It then calls mail_open() to submit
messages and exits with return code == number of successfully
submitted messages. forks() for each message are eliminated.
To be called as:
...
open(MA, "|/some/dir/mdist");
while (($to, $subj) = each %SUBSCRIBERS) {
print MA "From \n"; # only "From " matters
print MA "To: $to\n";
print MA "Subject: $subj\n";
print MA "Precedence: junk\n";
print MA "\n"; # End of headers
print MA "This is body of message.\n";
print MA "string 'From ' in beginning of line should be escaped.\n";
print MA ">From Russia with love.\n";
}
close(MA);
# Analyze $? if needed
...
This is a program itself (tab is 4 spaces):
#include <stdio.h>
#include <zmailer.h>
#define MailSep "From "
#define LineLen 16384
void main() {
unsigned char buf[LineLen];
FILE *of = NULL;
int MailSepLen, MsgCount = 0;
MailSepLen = strlen(MailSep);
while(fgets(buf, LineLen, stdin) != NULL) {
if (strncmp(MailSep, buf, MailSepLen) == 0) { /* Start new msg */
if (of != NULL) { /* Have open mail? */
if (mail_close(of) == EOF)
exit(MsgCount);
MsgCount++;
}
if ((of = mail_open(MSG_RFC822)) == NULL)
exit(MsgCount);
}
else {
if (of == NULL) /* Wrong first line */
exit(0);
if ((fputs(buf, of)) == EOF) { /* Output error */
(void) mail_abort(of);
exit(MsgCount);
}
}
}
if (of != NULL)
if (ferror(stdin))
(void) mail_abort(of);
else
if (mail_close(of) != EOF)
MsgCount++;
exit(MsgCount);
}
I interested in comments if it really speeds up mail submitting.
--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Joint stock company "GVC Energeticy", North-Caucasian Branch, Pyatigorsk
Andrew Petrovich Kokarev, postmaster andrew@skfgvc.pyatigorsk.su