James R Grinter wrote:
>I'm using Bruce Guenter's qmail-autoresponder (version 0.93) fairly
>successfully, but have just been trying to use the "-c" (Copy message
>into response) option.
>
>What I seem to end up with is the message there, but with each
>CRLF replaced with a NULL byte instead - and blank lines removed.
>
>What am I doing wrong?
>
Nothing. It seems to be a bug since I had exactly the same problem.
I've attached a patch that fixes this. But beware: I modified the
autoresponder so that it also attaches the old mail as an attachment. I
don't know, but it might be relatively easy to remove those additional
lines.
Ciao, Chtephan!
--- qmail-autoresponder.c.orig Mon Jul 31 07:16:27 2000
+++ qmail-autoresponder.c Thu Jun 21 16:27:11 2001
@@ -18,6 +18,7 @@
static time_t opt_timelimit = 3600;
static unsigned opt_maxmsgs = 1;
static const char* opt_subject_prefix = 0;
+static char boundary[128];
static int opt_msgfile;
static const char* argv0;
@@ -188,8 +189,10 @@
while(ptr < headerend) {
if(*ptr++ == '\n') {
if(ptr >= headerend || *ptr == '\n' || !isspace(*ptr)) {
+ char old_before = ptr[-1];
ptr[-1] = 0;
parse_header(start, ptr-start-1);
+ ptr[-1] = old_before;
break;
}
}
@@ -249,10 +252,12 @@
void parse_write_block(int fdout, const char* buf, size_t len)
{
static int saw_percent = 0;
+ static int saw_newline = 0;
while(len > 0) {
ssize_t todo;
ssize_t incr;
char* next;
+ char* next2;
if(saw_percent) {
write(2, "Delayed percent\n", 16);
saw_percent = 0;
@@ -268,12 +273,33 @@
break;
}
}
+ else if(saw_newline == 1) {
+ switch(*buf) {
+ case '\r':
+ case '\n':
+ write(fdout, "\n\n--", 4);
+ write(fdout, boundary, strlen(boundary));
+ write(fdout, "\n", 1);
+ saw_newline = 2;
+ break;
+ default:
+ saw_newline = 0;
+ }
+ }
next = memchr(buf, '%', len);
- if(next) {
+ if (opt_copyinput && saw_newline == 0)
+ next2 = memchr(buf, '\n', len);
+ else
+ next2 = NULL;
+ if(next && (!next2 || next < next2)) {
todo = next - buf;
incr = todo + 1;
saw_percent = 1;
}
+ else if(next2) {
+ incr = todo = next2 - buf + 1;
+ saw_newline = 1;
+ }
else
incr = todo = len;
if(write(fdout, buf, todo) != todo)
@@ -345,7 +371,8 @@
if(now-message_time > opt_timelimit) {
/* too old..ignore errors on unlink */
unlink(entry->d_name);
- } else {
+ }
+ else {
if(strcasecmp(end+1, sender_copy)==0)
/* If the user's count is already over the max,
* don't record any more. */
@@ -376,7 +403,7 @@
{
int fdout;
const char* sender;
-
+
parse_args(argc, argv);
// Fail if SENDER or DTLINE are not set
@@ -414,11 +441,44 @@
write(fdout, subject, subject_len);
write(fdout, "\n", 1);
}
+ if(opt_copyinput) {
+ const char *hostname;
+ FILE *f = fopen("/home/qmail/control/me", "r");
+ if(f) {
+ char *nl;
+ boundary[0] = 0;
+ fgets(boundary, sizeof boundary, f);
+ boundary[(sizeof boundary)-1] = 0;
+ fclose(f);
+ nl = strchr(boundary, '\n');
+ if (nl)
+ *nl = 0;
+ hostname = malloc(strlen(boundary)+1);
+ strcpy(hostname, boundary);
+ } else {
+ hostname = malloc(5);
+ strcpy(hostname, "mail");
+ }
+ snprintf(boundary, sizeof boundary, "%d%s%d", (int)time(NULL), hostname,
+getpid());
+ free(hostname);
+ boundary[(sizeof boundary)-1] = 0;
+ write(fdout, "MIME-Version: 1.0\n", 18);
+ write(fdout, "Content-Type: multipart/mixed; boundary=\"", 41);
+ write(fdout, boundary, strlen(boundary));
+ write(fdout, "\"\n", 2);
+ }
copy_msgfile(opt_msgfile, fdout);
close(opt_msgfile);
- if(opt_copyinput)
+ if(opt_copyinput) {
+ write(fdout, "\n--", 3);
+ write(fdout, boundary, strlen(boundary));
+ write(fdout, "\nContent-Type: message/rfc822\n\n", 31);
copy_input(fdout);
+ write(fdout, "--", 2);
+ write(fdout, boundary, strlen(boundary));
+ write(fdout, "--\n", 3);
+ }
if(opt_nosend)
close(1);