Create temporary mailbox instead of the temporary message, to avoid problems whe…
…n running sieve fileinto.
Showing
3 changed files
with
38 additions
and
40 deletions
... | @@ -100,15 +100,14 @@ extern int exit_code; | ... | @@ -100,15 +100,14 @@ extern int exit_code; |
100 | extern void setgroupquota __P((char *str)); | 100 | extern void setgroupquota __P((char *str)); |
101 | extern int check_quota __P((char *name, size_t size, size_t *rest)); | 101 | extern int check_quota __P((char *name, size_t size, size_t *rest)); |
102 | 102 | ||
103 | int mda __P((message_t msg, char *username)); | 103 | int mda __P((mailbox_t mbx, char *username)); |
104 | int switch_user_id __P((struct mu_auth_data *auth, int user)); | 104 | int switch_user_id __P((struct mu_auth_data *auth, int user)); |
105 | void mailer_err __P((char *fmt, ...)); | 105 | void mailer_err __P((char *fmt, ...)); |
106 | 106 | ||
107 | #ifdef WITH_GUILE | 107 | #ifdef WITH_GUILE |
108 | struct mda_data | 108 | struct mda_data |
109 | { | 109 | { |
110 | message_t msg; | 110 | mailbox_t mbox; |
111 | char *tempfile; | ||
112 | char *progfile; | 111 | char *progfile; |
113 | char *progfile_pattern; | 112 | char *progfile_pattern; |
114 | char **argv; | 113 | char **argv; | ... | ... |
... | @@ -34,12 +34,12 @@ mu_debug_t mudebug; | ... | @@ -34,12 +34,12 @@ mu_debug_t mudebug; |
34 | #define MAXFD 64 | 34 | #define MAXFD 64 |
35 | #define EX_QUOTA() (ex_quota_tempfail ? EX_TEMPFAIL : EX_UNAVAILABLE) | 35 | #define EX_QUOTA() (ex_quota_tempfail ? EX_TEMPFAIL : EX_UNAVAILABLE) |
36 | 36 | ||
37 | void close_fds (); | 37 | void close_fds __P((void)); |
38 | int make_tmp __P((const char *from, message_t *msg, char **tempfile)); | 38 | int make_tmp __P((const char *from, mailbox_t *mbx)); |
39 | void deliver (message_t msg, char *name); | 39 | void deliver __P((mailbox_t msg, char *name)); |
40 | void guess_retval (int ec); | 40 | void guess_retval __P((int ec)); |
41 | void mailer_err (char *fmt, ...); | 41 | void mailer_err __P((char *fmt, ...)); |
42 | void notify_biff (mailbox_t mbox, char *name, size_t size); | 42 | void notify_biff __P((mailbox_t mbox, char *name, size_t size)); |
43 | 43 | ||
44 | const char *argp_program_version = "mail.local (" PACKAGE_STRING ")"; | 44 | const char *argp_program_version = "mail.local (" PACKAGE_STRING ")"; |
45 | static char doc[] = | 45 | static char doc[] = |
... | @@ -265,8 +265,7 @@ _sieve_parse_error (void *user_name, const char *filename, int lineno, | ... | @@ -265,8 +265,7 @@ _sieve_parse_error (void *user_name, const char *filename, int lineno, |
265 | int | 265 | int |
266 | main (int argc, char *argv[]) | 266 | main (int argc, char *argv[]) |
267 | { | 267 | { |
268 | char *tempfile = NULL; | 268 | mailbox_t mbox = NULL; |
269 | message_t message = NULL; | ||
270 | int arg_index; | 269 | int arg_index; |
271 | 270 | ||
272 | /* Preparative work: close inherited fds, force a reasonable umask | 271 | /* Preparative work: close inherited fds, force a reasonable umask |
... | @@ -326,7 +325,7 @@ main (int argc, char *argv[]) | ... | @@ -326,7 +325,7 @@ main (int argc, char *argv[]) |
326 | list_append (bookie, smtp_record); | 325 | list_append (bookie, smtp_record); |
327 | } | 326 | } |
328 | 327 | ||
329 | if (make_tmp (from, &message, &tempfile)) | 328 | if (make_tmp (from, &mbox)) |
330 | exit (exit_code); | 329 | exit (exit_code); |
331 | 330 | ||
332 | if (multiple_delivery) | 331 | if (multiple_delivery) |
... | @@ -338,22 +337,20 @@ main (int argc, char *argv[]) | ... | @@ -338,22 +337,20 @@ main (int argc, char *argv[]) |
338 | struct mda_data mda_data; | 337 | struct mda_data mda_data; |
339 | 338 | ||
340 | memset (&mda_data, 0, sizeof mda_data); | 339 | memset (&mda_data, 0, sizeof mda_data); |
341 | mda_data.msg = message; | 340 | mda_data.mbox = mbox; |
342 | mda_data.argv = argv; | 341 | mda_data.argv = argv; |
343 | mda_data.progfile_pattern = progfile_pattern; | 342 | mda_data.progfile_pattern = progfile_pattern; |
344 | mda_data.tempfile = tempfile; | ||
345 | return prog_mda (&mda_data); | 343 | return prog_mda (&mda_data); |
346 | } | 344 | } |
347 | #endif | 345 | #endif |
348 | 346 | ||
349 | unlink (tempfile); | ||
350 | for (; *argv; argv++) | 347 | for (; *argv; argv++) |
351 | mda (message, *argv); | 348 | mda (mbox, *argv); |
352 | return exit_code; | 349 | return exit_code; |
353 | } | 350 | } |
354 | 351 | ||
355 | int | 352 | int |
356 | sieve_test (struct mu_auth_data *auth, message_t msg) | 353 | sieve_test (struct mu_auth_data *auth, mailbox_t mbx) |
357 | { | 354 | { |
358 | int rc = 1; | 355 | int rc = 1; |
359 | char *progfile; | 356 | char *progfile; |
... | @@ -388,7 +385,9 @@ sieve_test (struct mu_auth_data *auth, message_t msg) | ... | @@ -388,7 +385,9 @@ sieve_test (struct mu_auth_data *auth, message_t msg) |
388 | if (rc == 0) | 385 | if (rc == 0) |
389 | { | 386 | { |
390 | attribute_t attr; | 387 | attribute_t attr; |
388 | message_t msg = NULL; | ||
391 | 389 | ||
390 | mailbox_get_message (mbx, 1, &msg); | ||
392 | message_get_attribute (msg, &attr); | 391 | message_get_attribute (msg, &attr); |
393 | attribute_unset_deleted (attr); | 392 | attribute_unset_deleted (attr); |
394 | if (switch_user_id (auth, 1) == 0) | 393 | if (switch_user_id (auth, 1) == 0) |
... | @@ -411,9 +410,9 @@ sieve_test (struct mu_auth_data *auth, message_t msg) | ... | @@ -411,9 +410,9 @@ sieve_test (struct mu_auth_data *auth, message_t msg) |
411 | } | 410 | } |
412 | 411 | ||
413 | int | 412 | int |
414 | mda (message_t msg, char *username) | 413 | mda (mailbox_t mbx, char *username) |
415 | { | 414 | { |
416 | deliver (msg, username); | 415 | deliver (mbx, username); |
417 | 416 | ||
418 | if (multiple_delivery) | 417 | if (multiple_delivery) |
419 | exit_code = EX_OK; | 418 | exit_code = EX_OK; |
... | @@ -478,7 +477,7 @@ tmp_write (stream_t stream, off_t *poffset, char *buf, size_t len) | ... | @@ -478,7 +477,7 @@ tmp_write (stream_t stream, off_t *poffset, char *buf, size_t len) |
478 | } | 477 | } |
479 | 478 | ||
480 | int | 479 | int |
481 | make_tmp (const char *from, message_t *msg, char **tempfile) | 480 | make_tmp (const char *from, mailbox_t *mbox) |
482 | { | 481 | { |
483 | stream_t stream; | 482 | stream_t stream; |
484 | char *buf = NULL; | 483 | char *buf = NULL; |
... | @@ -487,9 +486,10 @@ make_tmp (const char *from, message_t *msg, char **tempfile) | ... | @@ -487,9 +486,10 @@ make_tmp (const char *from, message_t *msg, char **tempfile) |
487 | size_t line; | 486 | size_t line; |
488 | int status; | 487 | int status; |
489 | static char *newline = "\n"; | 488 | static char *newline = "\n"; |
489 | char *tempfile; | ||
490 | 490 | ||
491 | *tempfile = mu_tempname (NULL); | 491 | tempfile = mu_tempname (NULL); |
492 | if ((status = file_stream_create (&stream, *tempfile, MU_STREAM_RDWR))) | 492 | if ((status = file_stream_create (&stream, tempfile, MU_STREAM_RDWR))) |
493 | { | 493 | { |
494 | mailer_err ("unable to open temporary file: %s", mu_errstring (status)); | 494 | mailer_err ("unable to open temporary file: %s", mu_errstring (status)); |
495 | exit (exit_code); | 495 | exit (exit_code); |
... | @@ -557,6 +557,8 @@ make_tmp (const char *from, message_t *msg, char **tempfile) | ... | @@ -557,6 +557,8 @@ make_tmp (const char *from, message_t *msg, char **tempfile) |
557 | 557 | ||
558 | status = tmp_write (stream, &offset, newline, 1); | 558 | status = tmp_write (stream, &offset, newline, 1); |
559 | free (buf); | 559 | free (buf); |
560 | unlink (tempfile); | ||
561 | free (tempfile); | ||
560 | 562 | ||
561 | if (status) | 563 | if (status) |
562 | { | 564 | { |
... | @@ -566,9 +568,17 @@ make_tmp (const char *from, message_t *msg, char **tempfile) | ... | @@ -566,9 +568,17 @@ make_tmp (const char *from, message_t *msg, char **tempfile) |
566 | return status; | 568 | return status; |
567 | } | 569 | } |
568 | 570 | ||
569 | if ((status = message_create (msg, NULL)) == 0) | 571 | stream_flush (stream); |
570 | status = message_set_stream (*msg, stream, NULL); | 572 | if ((status = mailbox_create (mbox, "/dev/null")) |
573 | || (status = mailbox_open (*mbox, MU_STREAM_READ)) | ||
574 | || (status = mailbox_set_stream (*mbox, stream))) | ||
575 | { | ||
576 | mailer_err ("temporary file open error: %s", mu_errstring (status)); | ||
577 | stream_destroy (&stream, stream_get_owner (stream)); | ||
578 | return status; | ||
579 | } | ||
571 | 580 | ||
581 | status = mailbox_messages_count (*mbox, &n); | ||
572 | if (status) | 582 | if (status) |
573 | { | 583 | { |
574 | errno = status; | 584 | errno = status; |
... | @@ -582,7 +592,7 @@ make_tmp (const char *from, message_t *msg, char **tempfile) | ... | @@ -582,7 +592,7 @@ make_tmp (const char *from, message_t *msg, char **tempfile) |
582 | } | 592 | } |
583 | 593 | ||
584 | void | 594 | void |
585 | deliver (message_t msg, char *name) | 595 | deliver (mailbox_t imbx, char *name) |
586 | { | 596 | { |
587 | mailbox_t mbox; | 597 | mailbox_t mbox; |
588 | char *path; | 598 | char *path; |
... | @@ -602,14 +612,14 @@ deliver (message_t msg, char *name) | ... | @@ -602,14 +612,14 @@ deliver (message_t msg, char *name) |
602 | return; | 612 | return; |
603 | } | 613 | } |
604 | 614 | ||
605 | if (!sieve_test (auth, msg)) | 615 | if (!sieve_test (auth, imbx)) |
606 | { | 616 | { |
607 | exit_code = EX_OK; | 617 | exit_code = EX_OK; |
608 | mu_auth_data_free (auth); | 618 | mu_auth_data_free (auth); |
609 | return; | 619 | return; |
610 | } | 620 | } |
611 | 621 | ||
612 | if ((status = message_get_stream (msg, &istream)) != 0) | 622 | if ((status = mailbox_get_stream (imbx, &istream)) != 0) |
613 | { | 623 | { |
614 | mailer_err ("can't get input message stream: %s", mu_errstring (status)); | 624 | mailer_err ("can't get input message stream: %s", mu_errstring (status)); |
615 | mu_auth_data_free (auth); | 625 | mu_auth_data_free (auth); | ... | ... |
... | @@ -39,19 +39,8 @@ prog_mda (struct mda_data *data) | ... | @@ -39,19 +39,8 @@ prog_mda (struct mda_data *data) |
39 | x_argv[0] = "mail.local"; | 39 | x_argv[0] = "mail.local"; |
40 | x_argv[1] = NULL; | 40 | x_argv[1] = NULL; |
41 | 41 | ||
42 | message_get_stream (data->msg, &stream); | ||
43 | stream_flush (stream); | ||
44 | if (mailbox_create (&mbox, data->tempfile) | ||
45 | || mailbox_open (mbox, MU_STREAM_RDWR) != 0) | ||
46 | { | ||
47 | mailer_err ("can't open temporary storage"); | ||
48 | return EX_UNAVAILABLE; | ||
49 | } | ||
50 | |||
51 | unlink (data->tempfile); | ||
52 | |||
53 | param.debug_guile = debug_guile; | 42 | param.debug_guile = debug_guile; |
54 | param.mbox = mbox; | 43 | param.mbox = data->mbox; |
55 | param.user_name = NULL; | 44 | param.user_name = NULL; |
56 | param.init = mda_init; | 45 | param.init = mda_init; |
57 | param.catch_body = mda_catch_body; | 46 | param.catch_body = mda_catch_body; |
... | @@ -117,7 +106,7 @@ mda_catch_body (void *data, mailbox_t mbox) | ... | @@ -117,7 +106,7 @@ mda_catch_body (void *data, mailbox_t mbox) |
117 | return SCM_BOOL_F; | 106 | return SCM_BOOL_F; |
118 | 107 | ||
119 | mda_switch_to_user (NULL); | 108 | mda_switch_to_user (NULL); |
120 | mda (md->msg, md->argv[0]); | 109 | mda (md->mbox, md->argv[0]); |
121 | return SCM_BOOL_F; | 110 | return SCM_BOOL_F; |
122 | } | 111 | } |
123 | 112 | ... | ... |
-
Please register or sign in to post a comment