diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-12-29 00:41:36 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-12-29 00:41:36 +0200 |
commit | bb242e454d5cf8b0c6bb1ca5d009ec18e86c0c2b (patch) | |
tree | b8774822f727c02f6243fdb0934f54a4d9468287 /src/mail.c | |
parent | 8b95dd9319aa0b3847b8b4baf99a90258c25051a (diff) | |
download | wydawca-bb242e454d5cf8b0c6bb1ca5d009ec18e86c0c2b.tar.gz wydawca-bb242e454d5cf8b0c6bb1ca5d009ec18e86c0c2b.tar.bz2 |
Switch to Mailutils 3.x
Diffstat (limited to 'src/mail.c')
-rw-r--r-- | src/mail.c | 78 |
1 files changed, 33 insertions, 45 deletions
@@ -43,34 +43,26 @@ mail_init () logmsg (LOG_ERR, _("cannot create default mailer `%s': %s"), url, mu_strerror (rc)); } } } -struct mu_stream_handle -{ - mu_stream_t str; - mu_off_t off; -}; - static ssize_t mu_stream_data_read_cb (void *handle, void *buffer, size_t size) { - struct mu_stream_handle *mhp = handle; + mu_stream_t str = handle; size_t nread; int rc; - rc = mu_stream_read (mhp->str, buffer, size, mhp->off, &nread); + rc = mu_stream_read (str, buffer, size, &nread); if (rc) { logmsg (LOG_ERR, "mu_stream_read: %s", mu_strerror (rc)); errno = EIO; return -1; } - - mhp->off += nread; return nread; } static int check_sign_result (gpgme_sign_result_t result, gpgme_sig_mode_t type) { @@ -177,14 +169,13 @@ static int sign_message (mu_message_t *pmsg, const char *key) { mu_message_t msg = *pmsg; mu_message_t newmsg; mu_body_t body; mu_header_t hdr; - struct mu_stream_handle mhn; - mu_stream_t istr, ostr; + mu_stream_t istr, ostr, bodystr; int rc; struct gpgme_data_cbs cbs; gpgme_data_t input, output; gpgme_error_t err; char *buf = NULL; size_t size = 0; @@ -204,80 +195,70 @@ sign_message (mu_message_t *pmsg, const char *key) if ((rc = mu_message_get_body (msg, &body))) { logmsg (LOG_ERR, "mu_message_get_body: %s", mu_strerror (rc)); return 1; } - if ((rc = mu_body_get_stream (body, &mhn.str))) + if ((rc = mu_body_get_streamref (body, &bodystr))) { logmsg (LOG_ERR, "mu_message_get_stream: %s", mu_strerror (rc)); return 1; } - mu_stream_seek (mhn.str, 0, SEEK_SET); - mhn.off = 0; - memset (&cbs, 0, sizeof (cbs)); cbs.read = mu_stream_data_read_cb; - err = gpgme_data_new_from_cbs (&input, &cbs, &mhn); + err = gpgme_data_new_from_cbs (&input, &cbs, &bodystr); if (err) { logmsg (LOG_ERR, "gpgme_data_new_from_cbs: %s", gpgme_strerror (rc)); return 1; } rc = gpg_sign (&output, input, key); + mu_stream_unref (bodystr); if (rc) return 1; if (gpgme_data_seek (output, 0, SEEK_SET) == -1) { logmsg (LOG_ERR, "gpgme_data_seek: %s", strerror (errno)); return 1; } mu_message_create (&newmsg, NULL); - mu_message_get_stream (newmsg, &ostr); + mu_message_get_streamref (newmsg, &ostr); /* Copy headers */ mu_message_get_header (msg, &hdr); - mu_header_get_stream (hdr, &istr); - mu_stream_seek (istr, 0, SEEK_SET); - while ((rc = mu_stream_sequential_getline (istr, &buf, &size, &nread)) == 0 - && nread) - { - rc = mu_stream_sequential_write (ostr, buf, nread); - if (rc) - { - logmsg (LOG_ERR, "mu_stream_sequential_write: %s", - mu_strerror (rc)); - break; - } - } + mu_header_get_streamref (hdr, &istr); - if (rc == 0) + rc = mu_stream_copy (ostr, istr, 0, NULL); + if (rc) + logmsg (LOG_ERR, "mu_stream_copy: %s", mu_strerror (rc)); + else { while ((nread = gpgme_data_read (output, buf, size)) > 0) { - rc = mu_stream_sequential_write (ostr, buf, nread); + rc = mu_stream_write (ostr, buf, nread, NULL); if (rc) { - logmsg (LOG_ERR, "mu_stream_sequential_write: %s", - mu_strerror (rc)); + logmsg (LOG_ERR, "mu_stream_write: %s", mu_strerror (rc)); break; } } if (rc == 0) { mu_message_destroy (&msg, mu_message_get_owner (msg)); *pmsg = newmsg; } } + mu_stream_unref (istr); + mu_stream_unref (ostr); if (rc) mu_message_destroy (&newmsg, mu_message_get_owner (msg)); gpgme_data_release (output); free (buf); @@ -289,22 +270,25 @@ mail_send_message (mu_address_t rcpt, const char *text, const char *signer_key) { int rc; mu_message_t msg; mu_stream_t stream = NULL; mu_header_t hdr; - int mailer_flags = 0; static char *x_mailer = "wydawca (" PACKAGE_STRING ")"; size_t size; char *buf; const char *sval; - - mu_message_create (&msg, NULL); - mu_message_get_stream (msg, &stream); - mu_stream_write (stream, text, strlen (text), 0, NULL); + mu_static_memory_stream_create (&stream, text, strlen (text)); + rc = mu_stream_to_message (stream, &msg); + mu_stream_unref (stream); + if (rc) + { + logmsg (LOG_CRIT, _("cannot create message: %s"), mu_strerror (rc)); + return; + } mu_message_get_header (msg, &hdr); mu_header_append (hdr, "X-Mailer", x_mailer); if (rcpt) { mu_address_to_string (rcpt, NULL, 0, &size); @@ -323,22 +307,25 @@ mail_send_message (mu_address_t rcpt, const char *text, free (buf); } } if (debug_level > 1) { - mu_debug_t debug; - mu_mailer_get_debug (mailer, &debug); - mu_debug_set_level (debug, MU_DEBUG_TRACE | MU_DEBUG_PROT); + mu_debug_level_t level; + + mu_debug_get_category_level (MU_DEBCAT_MAILER, &level); + level |= MU_DEBUG_LEVEL_MASK (MU_DEBUG_TRACE0) | + MU_DEBUG_LEVEL_MASK (MU_DEBUG_PROT); if (debug_level > 2) - mailer_flags = MAILER_FLAG_DEBUG_DATA; + level |= MU_DEBUG_LEVEL_MASK (MU_DEBUG_TRACE7); + mu_debug_set_category_level (MU_DEBCAT_MAILER, level); } if (!mailer_opened) { - if ((rc = mu_mailer_open (mailer, mailer_flags))) + if ((rc = mu_mailer_open (mailer, 0))) { mu_url_t url = NULL; mu_mailer_get_url (mailer, &url); logmsg (LOG_CRIT, _("opening mailer `%s' failed: %s"), url ? mu_url_to_string (url) : "(unknown URL)", mu_strerror (rc)); @@ -727,6 +714,7 @@ expand_email_owner (struct metadef *def, void *data) mu_address_destroy (&addr); } else def->value = ""; return def->value; } + |