--- ../qmail-notify-0.91/qmail-notify.c Tue Nov 21 23:45:34 2000 +++ qmail-notify.c Wed Nov 22 00:47:43 2000 @@ -43,6 +40,7 @@ static int opt_checkrcpt = 0; static int opt_debug = 0; static int opt_nosend = 0; +static int opt_usemime = 0; static time_t opt_age = 4*60*60; static const char* extra_rcpt_name = "postmaster"; static ssize_t opt_msgbytes = -1; @@ -205,11 +203,39 @@ } } +char* mime_boundary[70]; + +void create_mime_boundary() +{ + time_t notify_pid; + int time_secs; + + notify_pid = getpid(); + time_secs = time(0); + snprintf(mime_boundary, 70, "MIME-Boundary-%d-%d", + (int)time_secs, (int)notify_pid); + if(opt_debug) + msgf("MIME boundary: \"%s\"", mime_boundary); +} + +static const char* bounce_mime_header = +"MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary=\"%s\" + +This is a multi-part message in MIME format. + +(If you can see this message, your E-mail client is not +MIME compatible. See RFC 1521 for more information). + +--%s +Content-Type: text/rfc822; charset=us-ascii + +"; + static const char* bounce_header = "From: To: <%s> Subject: delayed delivery notice - "; static const char* bounce_body = @@ -219,6 +245,23 @@ to these recipients for a total of %s. You do not need to resend your message at this time. + Recipient(s): +"; + +static const char* bounce_mime_footer = +" + +--%s-- + +"; + +static const char* message_mime_seperator = +" + +--%s +Content-Type: message/rfc822 +Content-Disposition: inline + "; static const char* message_seperator = @@ -233,7 +276,10 @@ char buf[4096]; if(fd == -1) die("Could not open message file"); - fputs(message_seperator, out); + if(opt_usemime) + fprintf(out, message_mime_seperator, mime_boundary); + else + fputs(message_seperator, out); if(opt_msgbytes < 0) for(;;) { ssize_t rd = read(fd, buf, sizeof buf); @@ -259,6 +305,8 @@ } close(fd); fputc('\n', out); + if (opt_usemime) + fprintf(out, bounce_mime_footer, mime_boundary); } void send_bounce(const char* sender, const char* filename, @@ -272,6 +320,11 @@ time2str(opt_age, time1); time2str(queuelifetime, time2); fprintf(out, bounce_header, me, sender); + if(opt_usemime) + { + create_mime_boundary(); + fprintf(out, bounce_mime_header, mime_boundary, mime_boundary); + } fprintf(out, bounce_body, me, time1, time2); for(ptr = locals; *ptr; ptr += strlen(ptr)+1) if(*ptr == 'T') @@ -398,6 +451,7 @@ msgf("now=%ld", now); msgf("lastrun=%ld", lastrun); msgf("opt_age=%ld", opt_age); + msgf("opt_usemime=%ld", opt_usemime); } } @@ -408,6 +462,7 @@ -d Show debugging messages. -h Show this usage help. -N Don't send messages, just print them out. + -m Use MIME to encapsulate messages. -r Only send to senders with a domain listed in qmail's rcpthosts. -t N Send notifications for messages that are N seconds old or older. (defaults to 4 hours) @@ -426,12 +481,13 @@ void parse_args(int argc, char* argv[]) { int ch; - while((ch = getopt(argc, argv, "b:dhNrt:x:")) != EOF) { + while((ch = getopt(argc, argv, "b:dhNmrt:x:")) != EOF) { switch(ch) { case 'b': opt_msgbytes = atoi(optarg); break; case 'd': opt_debug = 1; break; case 'h': usage(0); break; case 'N': opt_nosend = 1; break; + case 'm': opt_usemime = 1; break; case 'r': opt_checkrcpt = 1; break; case 't': opt_age = atoi(optarg); break; case 'x': extra_rcpt_name = optarg; break;