Commit b878341a b878341ae706413dd4a60d1cd65042d5e7b815d4 by Sergey Poznyakoff

Handle aliases.

1 parent 3493c914
Showing 1 changed file with 91 additions and 2 deletions
...@@ -33,7 +33,7 @@ static char args_doc[] = N_("file [file...]"); ...@@ -33,7 +33,7 @@ static char args_doc[] = N_("file [file...]");
33 /* GNU options */ 33 /* GNU options */
34 static struct argp_option options[] = { 34 static struct argp_option options[] = {
35 {"alias", ARG_ALIAS, N_("FILE"), 0, 35 {"alias", ARG_ALIAS, N_("FILE"), 0,
36 N_("* Specify additional alias file") }, 36 N_("Specify additional alias file") },
37 {"draft", ARG_DRAFT, NULL, 0, 37 {"draft", ARG_DRAFT, NULL, 0,
38 N_("Use prepared draft") }, 38 N_("Use prepared draft") },
39 {"draftfolder", ARG_DRAFTFOLDER, N_("FOLDER"), 0, 39 {"draftfolder", ARG_DRAFTFOLDER, N_("FOLDER"), 0,
...@@ -127,7 +127,8 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state) ...@@ -127,7 +127,8 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state)
127 switch (key) 127 switch (key)
128 { 128 {
129 case ARG_ALIAS: 129 case ARG_ALIAS:
130 return 1; 130 mh_alias_read (arg, 1);
131 break;
131 132
132 case ARG_DRAFT: 133 case ARG_DRAFT:
133 use_draft = 1; 134 use_draft = 1;
...@@ -346,6 +347,89 @@ get_sender_personal () ...@@ -346,6 +347,89 @@ get_sender_personal ()
346 return s; 347 return s;
347 } 348 }
348 349
350 static void
351 set_address_header (header_t hdr, char *name, address_t addr)
352 {
353 size_t s = address_format_string (addr, NULL, 0);
354 char *value = xmalloc (s + 1);
355 address_format_string (addr, value, s);
356 header_set_value (hdr, name, value, 1);
357 free (value);
358 }
359
360 void
361 expand_aliases (message_t msg)
362 {
363 header_t hdr;
364 size_t i, num;
365 char buf[16];
366 address_t addr_to = NULL,
367 addr_cc = NULL,
368 addr_bcc = NULL;
369
370 message_get_header (msg, &hdr);
371 header_get_field_count (hdr, &num);
372 for (i = 1; i <= num; i++)
373 {
374 header_get_field_name (hdr, i, buf, sizeof buf, NULL);
375 if (strcasecmp (buf, MU_HEADER_TO) == 0
376 || strcasecmp (buf, MU_HEADER_CC) == 0
377 || strcasecmp (buf, MU_HEADER_BCC) == 0)
378 {
379 char *value;
380 address_t addr = NULL;
381 int incl;
382
383 header_aget_field_value_unfold (hdr, i, &value);
384
385 mh_alias_expand (value, &addr, &incl);
386 free (value);
387 if (strcasecmp (buf, MU_HEADER_TO) == 0)
388 address_union (&addr_to, addr);
389 else if (strcasecmp (buf, MU_HEADER_CC) == 0)
390 address_union (&addr_cc, addr);
391 else if (strcasecmp (buf, MU_HEADER_BCC) == 0)
392 address_union (&addr_bcc, addr);
393 }
394 }
395
396 if (addr_to)
397 {
398 set_address_header (hdr, MU_HEADER_TO, addr_to);
399 address_destroy (&addr_to);
400 }
401
402 if (addr_cc)
403 {
404 set_address_header (hdr, MU_HEADER_CC, addr_cc);
405 address_destroy (&addr_cc);
406 }
407
408 if (addr_bcc)
409 {
410 set_address_header (hdr, MU_HEADER_BCC, addr_bcc);
411 address_destroy (&addr_bcc);
412 }
413 }
414
415 void
416 fix_fcc (message_t msg)
417 {
418 header_t hdr;
419 char *val;
420
421 message_get_header (msg, &hdr);
422 if (header_aget_value (hdr, MU_HEADER_FCC, &val) == 0
423 && strchr ("+%~/=", val[0]) == NULL)
424 {
425 val = realloc (val, strlen (val) + 2);
426 memmove (val + 1, val, strlen (val) + 1);
427 val[0] = '+';
428 header_set_value (hdr, MU_HEADER_FCC, val, 1);
429 free (val);
430 }
431 }
432
349 int 433 int
350 _action_send (void *item, void *data) 434 _action_send (void *item, void *data)
351 { 435 {
...@@ -388,6 +472,9 @@ _action_send (void *item, void *data) ...@@ -388,6 +472,9 @@ _action_send (void *item, void *data)
388 create_message_id (hdr); 472 create_message_id (hdr);
389 } 473 }
390 474
475 expand_aliases (msg);
476 fix_fcc (msg);
477
391 mailer = open_mailer (); 478 mailer = open_mailer ();
392 if (!mailer) 479 if (!mailer)
393 return 1; 480 return 1;
...@@ -447,6 +534,8 @@ main (int argc, char **argv) ...@@ -447,6 +534,8 @@ main (int argc, char **argv)
447 mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc, 534 mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
448 opt_handler, NULL, &index); 535 opt_handler, NULL, &index);
449 536
537 mh_read_aliases ();
538
450 argc -= index; 539 argc -= index;
451 argv += index; 540 argv += index;
452 541
......