aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-12-29 00:41:36 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2010-12-29 00:41:36 +0200
commitbb242e454d5cf8b0c6bb1ca5d009ec18e86c0c2b (patch)
treeb8774822f727c02f6243fdb0934f54a4d9468287 /src
parent8b95dd9319aa0b3847b8b4baf99a90258c25051a (diff)
downloadwydawca-bb242e454d5cf8b0c6bb1ca5d009ec18e86c0c2b.tar.gz
wydawca-bb242e454d5cf8b0c6bb1ca5d009ec18e86c0c2b.tar.bz2
Switch to Mailutils 3.x
Diffstat (limited to 'src')
-rw-r--r--src/config.c8
-rw-r--r--src/mail.c78
2 files changed, 33 insertions, 53 deletions
diff --git a/src/config.c b/src/config.c
index e46c2f5..9c75df6 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1152,14 +1152,6 @@ cb_url (enum grecs_callback_command cmd,
1152 value->v.string, mu_strerror (rc)); 1152 value->v.string, mu_strerror (rc));
1153 return rc; 1153 return rc;
1154 } 1154 }
1155 rc = mu_url_parse (url);
1156 if (rc)
1157 {
1158 grecs_error (locus, 0, _("cannot parse URL `%s': %s"),
1159 value->v.string, mu_strerror (rc));
1160 mu_url_destroy (&url);
1161 return rc;
1162 }
1163 *purl = url; 1155 *purl = url;
1164 return 0; 1156 return 0;
1165} 1157}
diff --git a/src/mail.c b/src/mail.c
index 39dfe08..afcf29e 100644
--- a/src/mail.c
+++ b/src/mail.c
@@ -46,28 +46,20 @@ mail_init ()
46 } 46 }
47} 47}
48 48
49struct mu_stream_handle
50{
51 mu_stream_t str;
52 mu_off_t off;
53};
54
55static ssize_t 49static ssize_t
56mu_stream_data_read_cb (void *handle, void *buffer, size_t size) 50mu_stream_data_read_cb (void *handle, void *buffer, size_t size)
57{ 51{
58 struct mu_stream_handle *mhp = handle; 52 mu_stream_t str = handle;
59 size_t nread; 53 size_t nread;
60 int rc; 54 int rc;
61 55
62 rc = mu_stream_read (mhp->str, buffer, size, mhp->off, &nread); 56 rc = mu_stream_read (str, buffer, size, &nread);
63 if (rc) 57 if (rc)
64 { 58 {
65 logmsg (LOG_ERR, "mu_stream_read: %s", mu_strerror (rc)); 59 logmsg (LOG_ERR, "mu_stream_read: %s", mu_strerror (rc));
66 errno = EIO; 60 errno = EIO;
67 return -1; 61 return -1;
68 } 62 }
69
70 mhp->off += nread;
71 return nread; 63 return nread;
72} 64}
73 65
@@ -180,8 +172,7 @@ sign_message (mu_message_t *pmsg, const char *key)
180 mu_message_t newmsg; 172 mu_message_t newmsg;
181 mu_body_t body; 173 mu_body_t body;
182 mu_header_t hdr; 174 mu_header_t hdr;
183 struct mu_stream_handle mhn; 175 mu_stream_t istr, ostr, bodystr;
184 mu_stream_t istr, ostr;
185 int rc; 176 int rc;
186 struct gpgme_data_cbs cbs; 177 struct gpgme_data_cbs cbs;
187 gpgme_data_t input, output; 178 gpgme_data_t input, output;
@@ -207,19 +198,16 @@ sign_message (mu_message_t *pmsg, const char *key)
207 return 1; 198 return 1;
208 } 199 }
209 200
210 if ((rc = mu_body_get_stream (body, &mhn.str))) 201 if ((rc = mu_body_get_streamref (body, &bodystr)))
211 { 202 {
212 logmsg (LOG_ERR, "mu_message_get_stream: %s", mu_strerror (rc)); 203 logmsg (LOG_ERR, "mu_message_get_stream: %s", mu_strerror (rc));
213 return 1; 204 return 1;
214 } 205 }
215 206
216 mu_stream_seek (mhn.str, 0, SEEK_SET);
217 mhn.off = 0;
218
219 memset (&cbs, 0, sizeof (cbs)); 207 memset (&cbs, 0, sizeof (cbs));
220 cbs.read = mu_stream_data_read_cb; 208 cbs.read = mu_stream_data_read_cb;
221 209
222 err = gpgme_data_new_from_cbs (&input, &cbs, &mhn); 210 err = gpgme_data_new_from_cbs (&input, &cbs, &bodystr);
223 if (err) 211 if (err)
224 { 212 {
225 logmsg (LOG_ERR, "gpgme_data_new_from_cbs: %s", 213 logmsg (LOG_ERR, "gpgme_data_new_from_cbs: %s",
@@ -228,6 +216,7 @@ sign_message (mu_message_t *pmsg, const char *key)
228 } 216 }
229 217
230 rc = gpg_sign (&output, input, key); 218 rc = gpg_sign (&output, input, key);
219 mu_stream_unref (bodystr);
231 if (rc) 220 if (rc)
232 return 1; 221 return 1;
233 222
@@ -238,33 +227,23 @@ sign_message (mu_message_t *pmsg, const char *key)
238 } 227 }
239 228
240 mu_message_create (&newmsg, NULL); 229 mu_message_create (&newmsg, NULL);
241 mu_message_get_stream (newmsg, &ostr); 230 mu_message_get_streamref (newmsg, &ostr);
242 231
243 /* Copy headers */ 232 /* Copy headers */
244 mu_message_get_header (msg, &hdr); 233 mu_message_get_header (msg, &hdr);
245 mu_header_get_stream (hdr, &istr); 234 mu_header_get_streamref (hdr, &istr);
246 mu_stream_seek (istr, 0, SEEK_SET);
247 while ((rc = mu_stream_sequential_getline (istr, &buf, &size, &nread)) == 0
248 && nread)
249 {
250 rc = mu_stream_sequential_write (ostr, buf, nread);
251 if (rc)
252 {
253 logmsg (LOG_ERR, "mu_stream_sequential_write: %s",
254 mu_strerror (rc));
255 break;
256 }
257 }
258 235
259 if (rc == 0) 236 rc = mu_stream_copy (ostr, istr, 0, NULL);
237 if (rc)
238 logmsg (LOG_ERR, "mu_stream_copy: %s", mu_strerror (rc));
239 else
260 { 240 {
261 while ((nread = gpgme_data_read (output, buf, size)) > 0) 241 while ((nread = gpgme_data_read (output, buf, size)) > 0)
262 { 242 {
263 rc = mu_stream_sequential_write (ostr, buf, nread); 243 rc = mu_stream_write (ostr, buf, nread, NULL);
264 if (rc) 244 if (rc)
265 { 245 {
266 logmsg (LOG_ERR, "mu_stream_sequential_write: %s", 246 logmsg (LOG_ERR, "mu_stream_write: %s", mu_strerror (rc));
267 mu_strerror (rc));
268 break; 247 break;
269 } 248 }
270 } 249 }
@@ -275,6 +254,8 @@ sign_message (mu_message_t *pmsg, const char *key)
275 *pmsg = newmsg; 254 *pmsg = newmsg;
276 } 255 }
277 } 256 }
257 mu_stream_unref (istr);
258 mu_stream_unref (ostr);
278 259
279 if (rc) 260 if (rc)
280 mu_message_destroy (&newmsg, mu_message_get_owner (msg)); 261 mu_message_destroy (&newmsg, mu_message_get_owner (msg));
@@ -292,16 +273,19 @@ mail_send_message (mu_address_t rcpt, const char *text,
292 mu_message_t msg; 273 mu_message_t msg;
293 mu_stream_t stream = NULL; 274 mu_stream_t stream = NULL;
294 mu_header_t hdr; 275 mu_header_t hdr;
295 int mailer_flags = 0;
296 static char *x_mailer = "wydawca (" PACKAGE_STRING ")"; 276 static char *x_mailer = "wydawca (" PACKAGE_STRING ")";
297 size_t size; 277 size_t size;
298 char *buf; 278 char *buf;
299 const char *sval; 279 const char *sval;
300
301 mu_message_create (&msg, NULL);
302 280
303 mu_message_get_stream (msg, &stream); 281 mu_static_memory_stream_create (&stream, text, strlen (text));
304 mu_stream_write (stream, text, strlen (text), 0, NULL); 282 rc = mu_stream_to_message (stream, &msg);
283 mu_stream_unref (stream);
284 if (rc)
285 {
286 logmsg (LOG_CRIT, _("cannot create message: %s"), mu_strerror (rc));
287 return;
288 }
305 mu_message_get_header (msg, &hdr); 289 mu_message_get_header (msg, &hdr);
306 mu_header_append (hdr, "X-Mailer", x_mailer); 290 mu_header_append (hdr, "X-Mailer", x_mailer);
307 291
@@ -326,16 +310,19 @@ mail_send_message (mu_address_t rcpt, const char *text,
326 310
327 if (debug_level > 1) 311 if (debug_level > 1)
328 { 312 {
329 mu_debug_t debug; 313 mu_debug_level_t level;
330 mu_mailer_get_debug (mailer, &debug); 314
331 mu_debug_set_level (debug, MU_DEBUG_TRACE | MU_DEBUG_PROT); 315 mu_debug_get_category_level (MU_DEBCAT_MAILER, &level);
316 level |= MU_DEBUG_LEVEL_MASK (MU_DEBUG_TRACE0) |
317 MU_DEBUG_LEVEL_MASK (MU_DEBUG_PROT);
332 if (debug_level > 2) 318 if (debug_level > 2)
333 mailer_flags = MAILER_FLAG_DEBUG_DATA; 319 level |= MU_DEBUG_LEVEL_MASK (MU_DEBUG_TRACE7);
320 mu_debug_set_category_level (MU_DEBCAT_MAILER, level);
334 } 321 }
335 322
336 if (!mailer_opened) 323 if (!mailer_opened)
337 { 324 {
338 if ((rc = mu_mailer_open (mailer, mailer_flags))) 325 if ((rc = mu_mailer_open (mailer, 0)))
339 { 326 {
340 mu_url_t url = NULL; 327 mu_url_t url = NULL;
341 mu_mailer_get_url (mailer, &url); 328 mu_mailer_get_url (mailer, &url);
@@ -730,3 +717,4 @@ expand_email_owner (struct metadef *def, void *data)
730 def->value = ""; 717 def->value = "";
731 return def->value; 718 return def->value;
732} 719}
720

Return to:

Send suggestions and report system problems to the System administrator.