reuse SLIST inlines.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
u->data = m_strdup(a->mailbox);
u->next = *expn;
*expn = u;
- w = rfc822_cpy_adr (t);
+ w = address_list_dup (t);
w = mutt_expand_aliases_r (w, expn);
if (head)
last->next = w;
abort ();
}
- *last = rfc822_cpy_adr (p);
+ *last = address_list_dup (p);
while (*last)
last = &((*last)->next);
}
#include <stdlib.h>
#include <lib-lib/mem.h>
+#include <lib-lib/list.h>
/* Content-Type */
enum {
DO_NEW(address_t, address);
DO_DELETE(address_t, address);
+DO_SLIST(address_t, address);
+
+address_t *address_dup(address_t *addr);
+address_t *address_list_dup(address_t *addr);
void rfc822_qualify(address_t *, const char *);
+
address_t *rfc822_parse_adrlist(address_t *, const char *s);
-address_t *rfc822_cpy_adr(address_t * addr);
-address_t *rfc822_cpy_adr_real(address_t * addr);
-address_t *rfc822_append(address_t ** a, address_t * b);
void rfc822_write_address(char *, size_t, address_t *, int);
void rfc822_write_address_single(char *, size_t, address_t *, int);
void rfc822_cat(char *, size_t, const char *, const char *);
void address_wipe(address_t *addr)
{
- address_delete(&addr->next);
p_delete(&addr->personal);
p_delete(&addr->mailbox);
+ address_delete(&addr->next);
+}
+
+
+void rfc822_qualify(address_t *addr, const char *host)
+{
+ char *p;
+
+ for (; addr; addr = addr->next) {
+ if (!addr->group && addr->mailbox && strchr(addr->mailbox, '@') == NULL) {
+ p = p_new(char, m_strlen(addr->mailbox) + m_strlen(host) + 2);
+ sprintf(p, "%s@%s", addr->mailbox, host); /* __SPRINTF_CHECKED__ */
+ p_delete(&addr->mailbox);
+ addr->mailbox = p;
+ }
+ }
+}
+
+address_t *address_dup(address_t *addr)
+{
+ address_t *res = address_new();
+
+ res->personal = m_strdup(addr->personal);
+ res->mailbox = m_strdup(addr->mailbox);
+ res->group = addr->group;
+ return res;
}
+address_t *address_list_dup(address_t *addr)
+{
+ address_t *res = NULL, **resp = &res;
+
+ for (; addr; addr = addr->next) {
+ *resp = address_dup(addr);
+ resp = &(*resp)->next;
+ }
+
+ return res;
+}
#define terminate_string(a, b, c) do { if ((b) < (c)) a[(b)] = 0; else \
a[(c)] = 0; } while (0)
return top;
}
-void rfc822_qualify (address_t * addr, const char *host)
-{
- char *p;
-
- for (; addr; addr = addr->next)
- if (!addr->group && addr->mailbox && strchr (addr->mailbox, '@') == NULL) {
- p = p_new(char, m_strlen(addr->mailbox) + m_strlen(host) + 2);
- sprintf (p, "%s@%s", addr->mailbox, host); /* __SPRINTF_CHECKED__ */
- p_delete(&addr->mailbox);
- addr->mailbox = p;
- }
-}
-
void
rfc822_cat (char *buf, size_t buflen, const char *value, const char *specials)
{
*pbuf = 0;
}
-/* this should be rfc822_cpy_adr */
-address_t *rfc822_cpy_adr_real (address_t * addr)
-{
- address_t *p = address_new ();
-
- p->personal = m_strdup(addr->personal);
- p->mailbox = m_strdup(addr->mailbox);
- p->group = addr->group;
- return p;
-}
-
-/* this should be rfc822_cpy_adrlist */
-address_t *rfc822_cpy_adr (address_t * addr)
-{
- address_t *top = NULL, *last = NULL;
-
- for (; addr; addr = addr->next) {
- if (last) {
- last->next = rfc822_cpy_adr_real (addr);
- last = last->next;
- }
- else
- top = last = rfc822_cpy_adr_real (addr);
- }
- return top;
-}
-
-/* append list 'b' to list 'a' and return the last element in the new list */
-address_t *rfc822_append (address_t ** a, address_t * b)
-{
- address_t *tmp = *a;
-
- while (tmp && tmp->next)
- tmp = tmp->next;
- if (!b)
- return tmp;
- if (tmp)
- tmp->next = rfc822_cpy_adr (b);
- else
- tmp = *a = rfc822_cpy_adr (b);
- while (tmp && tmp->next)
- tmp = tmp->next;
- return tmp;
-}
rfc822_parse_adrlist (hdr->env->return_path, return_path);
if (!hdr->env->from)
- hdr->env->from = rfc822_cpy_adr (hdr->env->return_path);
+ hdr->env->from = address_list_dup (hdr->env->return_path);
ctx->msgcount++;
}
rfc822_parse_adrlist (curhdr->env->return_path, return_path);
if (!curhdr->env->from)
- curhdr->env->from = rfc822_cpy_adr (curhdr->env->return_path);
+ curhdr->env->from = address_list_dup (curhdr->env->return_path);
lines = 0;
}
abort ();
}
- *last = rfc822_cpy_adr (p);
+ *last = address_list_dup (p);
while (*last)
last = &((*last)->next);
}
{
static address_t *tmp;
- tmp = rfc822_cpy_adr (r->addr);
+ tmp = address_list_dup (r->addr);
if (!tmp->next && !tmp->personal)
tmp->personal = m_strdup(r->name);
for (i = 0; i < menu->max; i++)
if (QueryTable[i].tagged) {
- address_t *a = result_to_addr (QueryTable[i].data);
-
- rfc822_append (&naddr, a);
- address_delete (&a);
+ address_list_append(&naddr, result_to_addr(QueryTable[i].data));
}
mutt_create_alias (NULL, naddr);
else {
for (i = 0; i < menu->max; i++)
if (QueryTable[i].tagged) {
- address_t *a = result_to_addr (QueryTable[i].data);
-
- rfc822_append (&msg->env->to, a);
- address_delete (&a);
+ address_list_append(&msg->env->to, result_to_addr(QueryTable[i].data));
}
}
ci_send_message (0, msg, NULL, Context, NULL);
for (; t; t = t->next) {
if (mutt_is_mail_list (t) && !t->group) {
if (top) {
- ptr->next = rfc822_cpy_adr_real (t);
+ ptr->next = address_dup (t);
ptr = ptr->next;
}
else
- ptr = top = rfc822_cpy_adr_real (t);
+ ptr = top = address_dup (t);
}
}
}
static int default_to (address_t ** to, ENVELOPE * env, int flags, int hmfupto)
{
char prompt[STRING];
- address_t *tmp;
if (flags && env->mail_followup_to && hmfupto == M_YES) {
- rfc822_append (to, env->mail_followup_to);
+ address_list_append(to, address_list_dup(env->mail_followup_to));
return 0;
}
_("Message came from a mailing list. List-reply to mailing list?")))
{
case M_YES:
- tmp = find_mailing_lists (env->to, env->cc);
- rfc822_append (to, tmp);
- address_delete (&tmp);
+ address_list_append(to, find_mailing_lists (env->to, env->cc));
return 0;
case -1:
return -1; /* abort */
if (!option (OPTREPLYSELF) && mutt_addr_is_user (env->from)) {
/* mail is from the user, assume replying to recipients */
- rfc822_append (to, env->to);
+ address_list_append(to, address_list_dup(env->to));
}
else if (env->reply_to) {
if ((mutt_addrcmp (env->from, env->reply_to) && !env->reply_to->next) ||
* in his From header.
*
*/
- rfc822_append (to, env->from);
+ address_list_append(to, address_list_dup(env->from));
}
else if (!(mutt_addrcmp (env->from, env->reply_to) &&
!env->reply_to->next) && quadoption (OPT_REPLYTO) != M_YES) {
env->reply_to->mailbox, env->reply_to->next ? ",..." : "");
switch (query_quadoption (OPT_REPLYTO, prompt)) {
case M_YES:
- rfc822_append (to, env->reply_to);
+ address_list_append(to, address_list_dup(env->reply_to));
break;
case M_NO:
- rfc822_append (to, env->from);
+ address_list_append(to, address_list_dup(env->from));
break;
default:
}
}
else
- rfc822_append (to, env->reply_to);
+ address_list_append(to, address_list_dup(env->reply_to));
}
else
- rfc822_append (to, env->from);
+ address_list_append(to, address_list_dup(env->from));
return (0);
}
int mutt_fetch_recips (ENVELOPE * out, ENVELOPE * in, int flags)
{
char prompt[STRING];
- address_t *tmp;
int hmfupto = -1;
if ((flags & (SENDLISTREPLY | SENDGROUPREPLY)) && in->mail_followup_to) {
}
if (flags & SENDLISTREPLY) {
- tmp = find_mailing_lists (in->to, in->cc);
- rfc822_append (&out->to, tmp);
- address_delete (&tmp);
+ address_list_append(&out->to, find_mailing_lists(in->to, in->cc));
if (in->mail_followup_to && hmfupto == M_YES &&
default_to (&out->cc, in, flags & SENDLISTREPLY, hmfupto) == -1)
return (-1); /* abort */
if ((flags & SENDGROUPREPLY)
- && (!in->mail_followup_to || hmfupto != M_YES)) {
- /* if(!mutt_addr_is_user(in->to)) */
- rfc822_append (&out->cc, in->to);
- rfc822_append (&out->cc, in->cc);
+ && (!in->mail_followup_to || hmfupto != M_YES))
+ {
+ address_t **tmp = address_list_append(&out->cc, address_list_dup(in->to));
+ address_list_append(tmp, address_list_dup(in->cc));
}
}
return 0;
void mutt_set_followup_to (ENVELOPE * e)
{
- address_t *t = NULL;
address_t *from;
/*
if (!e->mail_followup_to) {
if (mutt_is_list_cc (0, e->to, e->cc)) {
+ address_t **tmp;
/*
* this message goes to known mailing lists, so create a proper
* mail-followup-to header
*/
- t = rfc822_append (&e->mail_followup_to, e->to);
- rfc822_append (&t, e->cc);
+ tmp = address_list_append(&e->mail_followup_to, address_list_dup(e->to));
+ address_list_append(tmp, address_list_dup(e->cc));
}
/* remove ourselves from the mail-followup-to header */
if (e->mail_followup_to && !mutt_is_list_recipient (0, e->to, e->cc)) {
if (e->reply_to)
- from = rfc822_cpy_adr (e->reply_to);
+ from = address_list_dup (e->reply_to);
else if (e->from)
- from = rfc822_cpy_adr (e->from);
+ from = address_list_dup (e->from);
else
from = mutt_default_from ();
if (from) {
- /* Normally, this loop will not even be entered. */
- for (t = from; t && t->next; t = t->next);
-
- t->next = e->mail_followup_to; /* t cannot be NULL at this point. */
+ address_list_append(&from->next, e->mail_followup_to);
e->mail_followup_to = from;
}
}
- e->mail_followup_to = mutt_remove_duplicates (e->mail_followup_to);
+ e->mail_followup_to = mutt_remove_duplicates(e->mail_followup_to);
}
}
if (!tmp && mutt_addr_is_user (env->from))
tmp = env->from;
if (tmp) {
- tmp = rfc822_cpy_adr_real (tmp);
+ tmp = address_dup (tmp);
if (!option (OPTREVREAL))
p_delete(&tmp->personal);
if (!tmp->personal)
*/
if (From)
- adr = rfc822_cpy_adr_real (From);
+ adr = address_dup (From);
else if (option (OPTUSEDOMAIN)) {
adr = address_new ();
adr->mailbox = p_new(char, m_strlen(Username) + m_strlen(fqdn) + 2);
abort ();
}
- *last = rfc822_cpy_adr (p);
+ *last = address_list_dup (p);
while (*last)
last = &((*last)->next);
}