diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2004-04-27 11:41:31 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2004-04-27 11:41:31 +0000 |
commit | f619275dcc509b813f86b97691050964560d2005 (patch) | |
tree | dcef690b5757a37fd8464a35facde65ffa4952e2 /mail | |
parent | e89420c998f67b85dc7a20e52a16b6fdc18c454e (diff) | |
download | mailutils-f619275dcc509b813f86b97691050964560d2005.tar.gz mailutils-f619275dcc509b813f86b97691050964560d2005.tar.bz2 |
(mail_sender,mail_nosender,get_sender_address): New functions.
Diffstat (limited to 'mail')
-rw-r--r-- | mail/mail.h | 4 | ||||
-rw-r--r-- | mail/retain.c | 57 |
2 files changed, 61 insertions, 0 deletions
diff --git a/mail/mail.h b/mail/mail.h index 7b0e5b370..3692dcbf4 100644 --- a/mail/mail.h +++ b/mail/mail.h @@ -337,6 +337,10 @@ extern char *ml_readline_with_intr __P((char *prompt)); extern char *alias_expand __P ((char *name)); extern void alias_destroy __P ((char *name)); +extern int mail_sender __P ((int argc, char **argv)); +extern int mail_nosender __P ((int argc, char **argv)); +extern address_t get_sender_address __P((message_t msg)); + #define COMPOSE_APPEND 0 #define COMPOSE_REPLACE 1 #define COMPOSE_SINGLE_LINE 2 diff --git a/mail/retain.c b/mail/retain.c index 1d691ad16..c20343f70 100644 --- a/mail/retain.c +++ b/mail/retain.c @@ -20,6 +20,7 @@ static list_t retained_headers = NULL; static list_t ignored_headers = NULL; static list_t unfolded_headers = NULL; +static list_t sender_headers = NULL; static int process_list (int argc, char **argv, @@ -105,3 +106,59 @@ mail_header_is_visible (char *str) else return !util_slist_lookup (ignored_headers, str); } + +/* + * sender [header-field...] + */ + +int +mail_sender (int argc, char **argv) +{ + return process_list (argc, argv, &sender_headers, + util_slist_add, + N_("Sender address is obtained from the envelope\n")); +} + +int +mail_nosender (int argc, char **argv) +{ + if (argc == 1) + { + util_slist_destroy (&sender_headers); + fprintf (ofile, _("Sender address is obtained from the envelope\n")); + } + else + while (--argc) + util_slist_remove (&sender_headers, *++argv); + return 0; +} + + +address_t +get_sender_address (message_t msg) +{ + iterator_t itr; + header_t header = NULL; + address_t addr = NULL; + + if (message_get_header (msg, &header)) + return NULL; + + if (!sender_headers || iterator_create (&itr, sender_headers)) + return NULL; + + for (iterator_first (itr); !addr && !iterator_is_done (itr); + iterator_next (itr)) + { + char *name; + char *buf = NULL; + + iterator_current (itr, (void **)&name); + if (header_aget_value (header, name, &buf) == 0) + address_create (&addr, buf); + free (buf); + } + iterator_destroy (&itr); + return addr; +} + |