Commit 3460a801 3460a8017dc902e2ed7bfd389a78cb2c1303edff by Sergey Poznyakoff

(mu_mailer_send_message): Set envelope from address according to the underlying mailer type.

1 parent f5351ae2
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
41 #include <mailutils/mailbox.h> 41 #include <mailutils/mailbox.h>
42 #include <mailutils/message.h> 42 #include <mailutils/message.h>
43 #include <mailutils/argcv.h> 43 #include <mailutils/argcv.h>
44 #include <mailutils/mutil.h>
44 45
45 #include <mailer0.h> 46 #include <mailer0.h>
46 47
...@@ -295,33 +296,100 @@ save_fcc (mu_message_t msg) ...@@ -295,33 +296,100 @@ save_fcc (mu_message_t msg)
295 } 296 }
296 } 297 }
297 298
298 int 299 static int
299 mu_mailer_send_message (mu_mailer_t mailer, mu_message_t msg, 300 _set_from (mu_address_t *pfrom, mu_message_t msg, mu_address_t from,
300 mu_address_t from, mu_address_t to) 301 mu_mailer_t mailer)
301 { 302 {
302 int status; 303 int status = 0;
303 304 char *mail_from;
304 if (mailer == NULL || mailer->_send_message == NULL) 305 mu_header_t header = NULL;
305 return ENOSYS;
306 306
307 /* Common API checking. */ 307 *pfrom = NULL;
308 308
309 /* FIXME: this should be done in the concrete APIs, sendmail doesn't 309 /* Get MAIL_FROM from FROM, the message, or the environment. */
310 yet, though, so do it here. */ 310 if (!from)
311 if (from)
312 { 311 {
313 if ((status = mu_mailer_check_from (from)) != 0) 312 const char *type;
313
314 if ((status = mu_message_get_header (msg, &header)) != 0)
314 return status; 315 return status;
316
317 status = mu_header_aget_value (header, MU_HEADER_FROM, &mail_from);
318
319 switch (status)
320 {
321 default:
322 return status;
323
324 /* Use the From: header. */
325 case 0:
326 MAILER_DEBUG1 (mailer, MU_DEBUG_TRACE,
327 "mu_mailer_send_message(): using From: %s\n",
328 mail_from);
329
330 status = mu_address_create (pfrom, mail_from);
331 free (mail_from);
332 break;
333
334 case MU_ERR_NOENT:
335 if (mu_property_sget_value (mailer->property, "TYPE", &type) == 0
336 && strcmp (type, "SENDMAIL") == 0)
337 return 0;
338
339 /* Use the environment. */
340 mail_from = mu_get_user_email (NULL);
341
342 if (mail_from)
343 {
344 MAILER_DEBUG1 (mailer, MU_DEBUG_TRACE,
345 "mu_mailer_send_message(): using user's address: %s\n",
346 mail_from);
347 }
348 else
349 {
350 MAILER_DEBUG0 (mailer, MU_DEBUG_TRACE,
351 "mu_mailer_send_message(): no user's address, failing\n");
352 }
353
354 if (!mail_from)
355 return errno;
356
357 status = mu_address_create (pfrom, mail_from);
358 /* FIXME: should we add the From: header? */
359 break;
360 }
315 } 361 }
316 362
317 if (to) 363 return status;
364 }
365
366 int
367 mu_mailer_send_message (mu_mailer_t mailer, mu_message_t msg,
368 mu_address_t from, mu_address_t to)
369 {
370 int status;
371 mu_address_t sender_addr = NULL;
372
373 if (mailer == NULL)
374 return EINVAL;
375 if (mailer->_send_message == NULL)
376 return ENOSYS;
377
378 status = _set_from (&sender_addr, msg, from, mailer);
379 if (status)
380 return status;
381 if (sender_addr)
382 from = sender_addr;
383
384 if ((!from || (status = mu_mailer_check_from (from)) == 0)
385 && (!to || (status = mu_mailer_check_to (to)) == 0))
318 { 386 {
319 if ((status = mu_mailer_check_to (to)) != 0) 387 save_fcc (msg);
320 return status; 388 status = mailer->_send_message (mailer, msg, from, to);
321 } 389 }
322 390
323 save_fcc (msg); 391 mu_address_destroy (&sender_addr);
324 return mailer->_send_message (mailer, msg, from, to); 392 return status;
325 } 393 }
326 394
327 int 395 int
......