Commit 2f75b3b3 2f75b3b3c1dd5c4702193defe313a2417eddd15f by Sergey Poznyakoff

(mta_send): Fixed printing of envelope to addresses.

1 parent 6f3c7d02
...@@ -280,10 +280,47 @@ add_recipient (const char *name) ...@@ -280,10 +280,47 @@ add_recipient (const char *name)
280 return status; 280 return status;
281 } 281 }
282 282
283 /* Convert addr to a comma-separated list of email addresses,
284 suitable as an argument to RCPT TO command */
285 char *
286 address_email_string (address_t addr)
287 {
288 size_t count, i, n, length;
289 char *value, *p;
290
291 address_get_email_count (addr, &count);
292 length = 0;
293 for (i = 1; i <= count; i++)
294 {
295 char *str;
296 address_aget_email (recipients, i, &str);
297 length += strlen (str) + 3;
298 free (str);
299 }
300
301 value = malloc (length + 1);
302 if (!value)
303 {
304 mu_error ("%s: not enough memory", progname);
305 return NULL;
306 }
307 p = value;
308 for (i = 1; i <= count; i++)
309 {
310 *p++ = '<';
311 address_get_email (recipients, i, p, length - (p - value), &n);
312 p += n;
313 *p++ = '>';
314 if (i + 1 <= count)
315 *p++ = ',';
316 }
317 *p = 0;
318 return value;
319 }
320
283 int 321 int
284 mta_send (message_t msg) 322 mta_send (message_t msg)
285 { 323 {
286 int c;
287 size_t n; 324 size_t n;
288 char buffer[512]; 325 char buffer[512];
289 stream_t stream = NULL; 326 stream_t stream = NULL;
...@@ -297,21 +334,7 @@ mta_send (message_t msg) ...@@ -297,21 +334,7 @@ mta_send (message_t msg)
297 free (value); 334 free (value);
298 } 335 }
299 336
300 c = address_to_string (recipients, NULL, 0, &n); 337 value = address_email_string (recipients);
301 if (c)
302 {
303 mu_error ("%s: address_to_string failure: %s",
304 progname, mu_strerror (c));
305 return 1;
306 }
307 value = malloc (n + 1);
308 if (!value)
309 {
310 mu_error ("%s: not enough memory", progname);
311 return 1;
312 }
313
314 address_to_string (recipients, value, n + 1, &n);
315 fprintf (diag, "ENVELOPE TO: %s\n", value); 338 fprintf (diag, "ENVELOPE TO: %s\n", value);
316 free (value); 339 free (value);
317 340
......