diff options
Diffstat (limited to 'camel/providers/sendmail/camel-sendmail-transport.c')
-rw-r--r-- | camel/providers/sendmail/camel-sendmail-transport.c | 121 |
1 files changed, 33 insertions, 88 deletions
diff --git a/camel/providers/sendmail/camel-sendmail-transport.c b/camel/providers/sendmail/camel-sendmail-transport.c index 5d5df59a7c..604d7f293d 100644 --- a/camel/providers/sendmail/camel-sendmail-transport.c +++ b/camel/providers/sendmail/camel-sendmail-transport.c @@ -41,10 +41,8 @@ static char *get_name (CamelService *service, gboolean brief); -static gboolean sendmail_can_send (CamelTransport *transport, CamelMedium *message); -static gboolean sendmail_send (CamelTransport *transport, CamelMedium *message, - CamelException *ex); -static gboolean sendmail_send_to (CamelTransport *transport, CamelMedium *message, +static gboolean sendmail_send_to (CamelTransport *transport, + CamelMimeMessage *message, CamelAddress *from, CamelAddress *recipients, CamelException *ex); @@ -59,9 +57,6 @@ camel_sendmail_transport_class_init (CamelSendmailTransportClass *camel_sendmail /* virtual method overload */ camel_service_class->get_name = get_name; - - camel_transport_class->can_send = sendmail_can_send; - camel_transport_class->send = sendmail_send; camel_transport_class->send_to = sendmail_send_to; } @@ -86,22 +81,40 @@ camel_sendmail_transport_get_type (void) static gboolean -sendmail_can_send (CamelTransport *transport, CamelMedium *message) -{ - return CAMEL_IS_MIME_MESSAGE (message); -} - - -static gboolean -sendmail_send_internal (CamelMedium *message, const char **argv, CamelException *ex) +sendmail_send_to (CamelTransport *transport, CamelMimeMessage *message, + CamelAddress *from, CamelAddress *recipients, + CamelException *ex) { - int fd[2], nullfd, wstat; + const char *from_addr, *addr, **argv; + int i, len, fd[2], nullfd, wstat; sigset_t mask, omask; CamelStream *out; pid_t pid; - g_assert (CAMEL_IS_MIME_MESSAGE (message)); - + if (!camel_internet_address_get (CAMEL_INTERNET_ADDRESS (from), 0, NULL, &from_addr)) + return FALSE; + + len = camel_address_length (recipients); + argv = g_malloc ((len + 6) * sizeof (char *)); + argv[0] = "sendmail"; + argv[1] = "-i"; + argv[2] = "-f"; + argv[3] = from_addr; + argv[4] = "--"; + + for (i = 0; i < len; i++) { + if (!camel_internet_address_get (CAMEL_INTERNET_ADDRESS (recipients), i, NULL, &addr)) { + camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, + _("Could not parse recipient list")); + g_free (argv); + return FALSE; + } + + argv[i + 5] = addr; + } + + argv[i + 5] = NULL; + if (pipe (fd) == -1) { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Could not create pipe to sendmail: " @@ -125,6 +138,7 @@ sendmail_send_internal (CamelMedium *message, const char **argv, CamelException "%s: mail not sent"), g_strerror (errno)); sigprocmask (SIG_SETMASK, &omask, NULL); + g_free (argv); return FALSE; case 0: @@ -139,6 +153,7 @@ sendmail_send_internal (CamelMedium *message, const char **argv, CamelException execv (SENDMAIL_PATH, (char **)argv); _exit (255); } + g_free (argv); /* Parent process. Write the message out. */ close (fd[0]); @@ -182,76 +197,6 @@ sendmail_send_internal (CamelMedium *message, const char **argv, CamelException return TRUE; } -static const char * -get_from (CamelMedium *message, CamelException *ex) -{ - const CamelInternetAddress *from; - const char *name, *address; - - from = camel_mime_message_get_from (CAMEL_MIME_MESSAGE (message)); - if (!from || !camel_internet_address_get (from, 0, &name, &address)) { - camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - _("Could not find 'From' address in message")); - return NULL; - } - return address; -} - -static gboolean -sendmail_send_to (CamelTransport *transport, CamelMedium *message, - CamelAddress *from, CamelAddress *recipients, - CamelException *ex) -{ - const char *from_addr, *addr, **argv; - gboolean status; - int i, len; - - if (!from) - return FALSE; - - if (!camel_internet_address_get (CAMEL_INTERNET_ADDRESS (from), 0, NULL, &from_addr)) - return FALSE; - - len = camel_address_length (recipients); - argv = g_malloc ((len + 6) * sizeof (char *)); - argv[0] = "sendmail"; - argv[1] = "-i"; - argv[2] = "-f"; - argv[3] = from_addr; - argv[4] = "--"; - - for (i = 0; i < len; i++) { - if (!camel_internet_address_get (CAMEL_INTERNET_ADDRESS (recipients), i, NULL, &addr)) { - camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, - _("Could not parse recipient list")); - g_free (argv); - return FALSE; - } - - argv[i + 5] = addr; - } - - argv[i + 5] = NULL; - - status = sendmail_send_internal (message, argv, ex); - g_free (argv); - - return status; -} - -static gboolean -sendmail_send (CamelTransport *transport, CamelMedium *message, - CamelException *ex) -{ - const char *argv[6] = { "sendmail", "-t", "-i", "-f", NULL, NULL }; - - argv[4] = get_from (message, ex); - if (!argv[4]) - return FALSE; - - return sendmail_send_internal (message, argv, ex); -} - static char * get_name (CamelService *service, gboolean brief) { |