static int moderator_discard_message (mu_sieve_machine_t mach, mu_message_t request, const char *from) { int rc; mu_message_t reply; mu_header_t repl_hdr, req_hdr; mu_mailer_t mailer; rc = mu_message_create (&reply, NULL); if (rc) return rc; rc = mu_message_get_header (reply, &repl_hdr); if (rc) { mu_message_destroy (&reply, NULL); return rc; } rc = mu_message_get_header (request, &req_hdr); if (rc) { mu_message_destroy (&reply, NULL); return rc; } if (copy_header (mach, repl_hdr, MU_HEADER_TO, req_hdr, MU_HEADER_FROM) || copy_header (mach, repl_hdr, MU_HEADER_SUBJECT, req_hdr, MU_HEADER_SUBJECT)) { mu_message_destroy (&reply, NULL); return rc; } if (from) mu_header_set_value (repl_hdr, MU_HEADER_FROM, from, 0); mailer = mu_sieve_get_mailer (mach); rc = mu_mailer_open (mailer, 0); if (rc) mu_sieve_error (mach, _("cannot open mailer: %s"), mu_strerror (rc)); else { rc = mu_mailer_send_message (mailer, reply, NULL, NULL); mu_mailer_close (mailer); if (rc) mu_sieve_error (mach, _("cannot send message: %s"), mu_strerror (rc)); } mu_message_destroy (&reply, NULL); return rc; }
/* Generate and send the reply message */ static int vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, mu_message_t msg, char *text, char *to, char *from) { mu_mime_t mime = NULL; mu_message_t newmsg; mu_header_t newhdr; mu_address_t to_addr = NULL, from_addr = NULL; char *value; mu_mailer_t mailer; int rc; if (mu_sieve_tag_lookup (tags, "file", NULL)) { mu_stream_t instr; rc = mu_mapfile_stream_create (&instr, text, MU_STREAM_READ); if (rc) { mu_sieve_error (mach, _("%lu: cannot open message file %s: %s"), (unsigned long) mu_sieve_get_message_num (mach), text, mu_strerror (rc)); return -1; } rc = mu_stream_to_message (instr, &newmsg); mu_stream_unref (instr); if (rc) { mu_sieve_error (mach, _("%lu: cannot read message from file %s: %s"), (unsigned long) mu_sieve_get_message_num (mach), text, mu_strerror (rc)); return -1; } } else { if (build_mime (mach, tags, &mime, msg, text)) return -1; mu_mime_get_message (mime, &newmsg); mu_message_unref (newmsg); mu_message_get_header (newmsg, &newhdr); } rc = mu_address_create (&to_addr, to); if (rc) { mu_sieve_error (mach, _("%lu: cannot create recipient address <%s>: %s"), (unsigned long) mu_sieve_get_message_num (mach), from, mu_strerror (rc)); } else { mu_header_set_value (newhdr, MU_HEADER_TO, to, 0); vacation_subject (mach, tags, msg, newhdr); if (from) { if (mu_address_create (&from_addr, from)) from_addr = NULL; } else { from_addr = NULL; } if (mu_rfc2822_in_reply_to (msg, &value) == 0) { mu_header_set_value (newhdr, MU_HEADER_IN_REPLY_TO, value, 1); free (value); } if (mu_rfc2822_references (msg, &value) == 0) { mu_header_set_value (newhdr, MU_HEADER_REFERENCES, value, 1); free (value); } mailer = mu_sieve_get_mailer (mach); if (mailer) { rc = mu_mailer_send_message (mailer, newmsg, from_addr, to_addr); } else rc = MU_ERR_FAILURE; } mu_address_destroy (&to_addr); mu_address_destroy (&from_addr); mu_mime_destroy (&mime); return rc; }