Sent empty messages only if nullbody is set
Showing
1 changed file
with
48 additions
and
24 deletions
... | @@ -307,6 +307,43 @@ compose_destroy (compose_env_t * env) | ... | @@ -307,6 +307,43 @@ compose_destroy (compose_env_t * env) |
307 | } | 307 | } |
308 | } | 308 | } |
309 | 309 | ||
310 | static int | ||
311 | fill_body (mu_message_t msg, FILE *file) | ||
312 | { | ||
313 | mu_body_t body = NULL; | ||
314 | mu_stream_t stream = NULL; | ||
315 | off_t offset = 0; | ||
316 | char *buf = NULL; | ||
317 | size_t n = 0; | ||
318 | mu_message_get_body (msg, &body); | ||
319 | mu_body_get_stream (body, &stream); | ||
320 | |||
321 | while (getline (&buf, &n, file) >= 0) | ||
322 | { | ||
323 | size_t len = strlen (buf); | ||
324 | mu_stream_write (stream, buf, len, offset, &n); | ||
325 | offset += len; | ||
326 | } | ||
327 | |||
328 | if (buf) | ||
329 | free (buf); | ||
330 | |||
331 | if (offset == 0) | ||
332 | { | ||
333 | if (util_getenv (NULL, "nullbody", Mail_env_boolean, 0) == 0) | ||
334 | { | ||
335 | char *str; | ||
336 | if (util_getenv (&str, "nullbodymsg", Mail_env_string, 0) == 0) | ||
337 | util_error ("%s\n", _(str)); | ||
338 | } | ||
339 | else | ||
340 | return 1; | ||
341 | } | ||
342 | |||
343 | return 0; | ||
344 | } | ||
345 | |||
346 | |||
310 | /* mail_send0(): shared between mail_send() and mail_reply(); | 347 | /* mail_send0(): shared between mail_send() and mail_reply(); |
311 | 348 | ||
312 | If the variable "record" is set, the outgoing message is | 349 | If the variable "record" is set, the outgoing message is |
... | @@ -492,35 +529,18 @@ mail_send0 (compose_env_t * env, int save_to) | ... | @@ -492,35 +529,18 @@ mail_send0 (compose_env_t * env, int save_to) |
492 | { | 529 | { |
493 | mu_mailer_t mailer; | 530 | mu_mailer_t mailer; |
494 | mu_message_t msg = NULL; | 531 | mu_message_t msg = NULL; |
532 | int rc; | ||
495 | 533 | ||
496 | mu_message_create (&msg, NULL); | 534 | mu_message_create (&msg, NULL); |
497 | 535 | ||
498 | mu_message_set_header (msg, env->header, NULL); | 536 | mu_message_set_header (msg, env->header, NULL); |
499 | 537 | ||
500 | /* Fill the body. */ | 538 | /* Fill the body. */ |
501 | { | 539 | rc = fill_body (msg, file); |
502 | mu_body_t body = NULL; | ||
503 | mu_stream_t stream = NULL; | ||
504 | off_t offset = 0; | ||
505 | char *buf = NULL; | ||
506 | size_t n = 0; | ||
507 | mu_message_get_body (msg, &body); | ||
508 | mu_body_get_stream (body, &stream); | ||
509 | while (getline (&buf, &n, file) >= 0) | ||
510 | { | ||
511 | size_t len = strlen (buf); | ||
512 | mu_stream_write (stream, buf, len, offset, &n); | ||
513 | offset += len; | ||
514 | } | ||
515 | |||
516 | if (offset == 0) | ||
517 | util_error (_("Null message body; hope that's ok\n")); | ||
518 | if (buf) | ||
519 | free (buf); | ||
520 | } | ||
521 | |||
522 | fclose (file); | 540 | fclose (file); |
523 | 541 | ||
542 | if (rc == 0) | ||
543 | { | ||
524 | /* Save outgoing message */ | 544 | /* Save outgoing message */ |
525 | if (save_to) | 545 | if (save_to) |
526 | { | 546 | { |
... | @@ -555,7 +575,8 @@ mail_send0 (compose_env_t * env, int save_to) | ... | @@ -555,7 +575,8 @@ mail_send0 (compose_env_t * env, int save_to) |
555 | { | 575 | { |
556 | int status; | 576 | int status; |
557 | mu_mailbox_t mbx = NULL; | 577 | mu_mailbox_t mbx = NULL; |
558 | status = mu_mailbox_create_default (&mbx, env->outfiles[i]); | 578 | status = mu_mailbox_create_default (&mbx, |
579 | env->outfiles[i]); | ||
559 | if (status == 0) | 580 | if (status == 0) |
560 | { | 581 | { |
561 | status = mu_mailbox_open (mbx, MU_STREAM_WRITE | 582 | status = mu_mailbox_open (mbx, MU_STREAM_WRITE |
... | @@ -583,7 +604,8 @@ mail_send0 (compose_env_t * env, int save_to) | ... | @@ -583,7 +604,8 @@ mail_send0 (compose_env_t * env, int save_to) |
583 | || compose_header_get (env, MU_HEADER_BCC, NULL)) | 604 | || compose_header_get (env, MU_HEADER_BCC, NULL)) |
584 | { | 605 | { |
585 | char *sendmail; | 606 | char *sendmail; |
586 | if (util_getenv (&sendmail, "sendmail", Mail_env_string, 0) == 0) | 607 | if (util_getenv (&sendmail, "sendmail", Mail_env_string, 0) |
608 | == 0) | ||
587 | { | 609 | { |
588 | int status = mu_mailer_create (&mailer, sendmail); | 610 | int status = mu_mailer_create (&mailer, sendmail); |
589 | if (status == 0) | 611 | if (status == 0) |
... | @@ -594,7 +616,8 @@ mail_send0 (compose_env_t * env, int save_to) | ... | @@ -594,7 +616,8 @@ mail_send0 (compose_env_t * env, int save_to) |
594 | mu_debug_t debug = NULL; | 616 | mu_debug_t debug = NULL; |
595 | mu_mailer_get_debug (mailer, &debug); | 617 | mu_mailer_get_debug (mailer, &debug); |
596 | mu_debug_set_level (debug, | 618 | mu_debug_set_level (debug, |
597 | MU_DEBUG_TRACE | MU_DEBUG_PROT); | 619 | MU_DEBUG_TRACE | |
620 | MU_DEBUG_PROT); | ||
598 | } | 621 | } |
599 | status = mu_mailer_open (mailer, MU_STREAM_RDWR); | 622 | status = mu_mailer_open (mailer, MU_STREAM_RDWR); |
600 | if (status == 0) | 623 | if (status == 0) |
... | @@ -610,6 +633,7 @@ mail_send0 (compose_env_t * env, int save_to) | ... | @@ -610,6 +633,7 @@ mail_send0 (compose_env_t * env, int save_to) |
610 | else | 633 | else |
611 | util_error (_("Variable sendmail not set: no mailer")); | 634 | util_error (_("Variable sendmail not set: no mailer")); |
612 | } | 635 | } |
636 | } | ||
613 | mu_message_destroy (&msg, NULL); | 637 | mu_message_destroy (&msg, NULL); |
614 | remove (filename); | 638 | remove (filename); |
615 | free (filename); | 639 | free (filename); | ... | ... |
-
Please register or sign in to post a comment