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; }
int mutool_send (int argc, char **argv) { int index; char *infile; mu_stream_t instr; mu_message_t msg; size_t count; mu_url_t urlhint, url; mu_mailer_t mailer; MU_ASSERT (mu_address_create_null (&rcpt_addr)); mu_register_all_mailer_formats (); if (argp_parse (&send_argp, argc, argv, 0, &index, NULL)) return 1; argc -= index; argv += index; if (argc < 1) { mu_error (_("not enough arguments")); return 1; } infile = argv[1]; if (infile) MU_ASSERT (mu_file_stream_create (&instr, infile, MU_STREAM_READ|MU_STREAM_SEEK)); else MU_ASSERT (mu_stdio_stream_create (&instr, MU_STDIN_FD, MU_STREAM_READ|MU_STREAM_SEEK)); MU_ASSERT (mu_stream_to_message (instr, &msg)); mu_stream_unref (instr); mu_address_get_count (rcpt_addr, &count); if (count == 0) read_recipients = 1; if (read_recipients) { int rc; mu_header_t header; const char *value; MU_ASSERT (mu_message_get_header (msg, &header)); rc = mu_header_sget_value (header, MU_HEADER_TO, &value); if (rc == 0) send_address_add (&rcpt_addr, value); else if (rc != MU_ERR_NOENT) { mu_diag_funcall (MU_DIAG_ERROR, "mu_header_sget_value", MU_HEADER_TO, rc); exit (1); } rc = mu_header_sget_value (header, MU_HEADER_CC, &value); if (rc == 0) send_address_add (&rcpt_addr, value); else if (rc != MU_ERR_NOENT) { mu_diag_funcall (MU_DIAG_ERROR, "mu_header_sget_value", MU_HEADER_CC, rc); exit (1); } rc = mu_header_sget_value (header, MU_HEADER_BCC, &value); if (rc == 0) send_address_add (&rcpt_addr, value); else if (rc != MU_ERR_NOENT) { mu_diag_funcall (MU_DIAG_ERROR, "mu_header_sget_value", MU_HEADER_BCC, rc); exit (1); } } mu_address_get_count (rcpt_addr, &count); if (count == 0) { mu_error (_("no recipients")); exit (1); } MU_ASSERT (mu_url_create (&urlhint, "smtp://")); MU_ASSERT (mu_url_create_hint (&url, argv[0], MU_URL_PARSE_DEFAULT, urlhint)); mu_url_invalidate (url); MU_ASSERT (mu_mailer_create_from_url (&mailer, url)); MU_ASSERT (mu_mailer_open (mailer, MU_STREAM_RDWR)); MU_ASSERT (mu_mailer_send_message (mailer, msg, from_addr, rcpt_addr)); mu_mailer_close (mailer); mu_mailer_destroy (&mailer); return 0; }