Commit 81dca07b 81dca07b3d80f65dbb635a908f51020942265e73 by Sergey Poznyakoff

Use mu_address_sget functions, where possible.

1 parent c4226486
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2001, 2004, 2005,
2007 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -32,7 +33,7 @@ parse (const char *str)
size_t no = 0;
size_t pcount = 0;
int status;
char buf[BUFSIZ];
const char *buf;
mu_address_t address = NULL;
mu_set_user_email_domain ("localhost");
......@@ -59,37 +60,32 @@ parse (const char *str)
if (isgroup)
{
mu_address_get_personal (address, no, buf, sizeof (buf), &got);
mu_address_sget_personal (address, no, &buf);
printf ("group <%s>\n", buf);
}
else
{
mu_address_get_email (address, no, buf, sizeof (buf), 0);
mu_address_sget_email (address, no, &buf);
printf ("email <%s>\n", buf);
}
mu_address_get_personal (address, no, buf, sizeof (buf), &got);
if (got && !isgroup)
if (mu_address_sget_personal (address, no, &buf) == 0 && buf && !isgroup)
printf (" personal <%s>\n", buf);
mu_address_get_comments (address, no, buf, sizeof (buf), &got);
if (got)
if (mu_address_sget_comments (address, no, &buf) == 0 && buf)
printf (" comments <%s>\n", buf);
mu_address_get_local_part (address, no, buf, sizeof (buf), &got);
if (got)
if (mu_address_sget_local_part (address, no, &buf) == 0 && buf)
{
printf (" local-part <%s>", buf);
mu_address_get_domain (address, no, buf, sizeof (buf), &got);
if (got)
if (mu_address_sget_domain (address, no, &buf) == 0 && buf)
printf (" domain <%s>", buf);
printf ("\n");
}
mu_address_get_route (address, no, buf, sizeof (buf), &got);
if (got)
if (mu_address_sget_route (address, no, &buf) == 0 && buf)
printf (" route <%s>\n", buf);
}
mu_address_destroy (&address);
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2005 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2001, 2005, 2007 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -281,10 +281,9 @@ address_email_string (mu_address_t addr)
length = 0;
for (i = 1; i <= count; i++)
{
char *str;
mu_address_aget_email (recipients, i, &str);
const char *str;
mu_address_sget_email (recipients, i, &str);
length += strlen (str) + 3;
free (str);
}
value = malloc (length + 1);
......
......@@ -358,7 +358,7 @@ init_output (size_t s)
from `from/from.c' and `mail/util.c'...
*/
static char *
rfc2047_decode_wrapper (char *buf, size_t buflen)
rfc2047_decode_wrapper (const char *buf, size_t buflen)
{
int rc;
char *tmp;
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2001, 2005, 2006 Free Software Foundation, Inc.
Copyright (C) 1999, 2001, 2005, 2006, 2007 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -1433,8 +1433,6 @@ fetch_header_fields_not (mu_message_t msg, char **arg, unsigned long start,
return RESP_OK;
}
/* FIXME: The address is limit by a buffer of 128, no good. We should
allocate the buffer. */
static int
fetch_send_address (const char *addr)
{
......@@ -1461,39 +1459,33 @@ fetch_send_address (const char *addr)
util_send ("(", count);
for (i = 1; i <= count; i++)
{
char buf[128];
const char *str;
int is_group = 0;
util_send ("(");
*buf = '\0';
mu_address_get_personal (address, i, buf, sizeof (buf), NULL);
util_send_qstring (buf);
mu_address_sget_personal (address, i, &str);
util_send_qstring (str);
util_send (" ");
*buf = '\0';
mu_address_get_route (address, i, buf, sizeof (buf), NULL);
util_send_qstring (buf);
mu_address_sget_route (address, i, &str);
util_send_qstring (str);
util_send (" ");
*buf = '\0';
{
int is_group = 0;
mu_address_is_group (address, i, &is_group);
str = NULL;
if (is_group)
mu_address_sget_personal (address, i, &str);
else
mu_address_sget_local_part (address, i, &str);
mu_address_is_group (address, i, &is_group);
if (is_group)
mu_address_get_personal (address, i, buf, sizeof (buf), NULL);
else
mu_address_get_local_part (address, i, buf, sizeof (buf), NULL);
}
util_send_qstring (buf);
util_send_qstring (str);
util_send (" ");
*buf = '\0';
mu_address_get_domain (address, i, buf, sizeof (buf), NULL);
util_send_qstring (buf);
mu_address_sget_domain (address, i, &str);
util_send_qstring (str);
util_send (")");
}
......
......@@ -54,19 +54,20 @@ _get_envelope_sender (mu_envelope_t env)
{
mu_address_t addr;
char buffer[128];
char *ptr;
if (mu_envelope_sender (env, buffer, sizeof (buffer), NULL)
|| mu_address_create (&addr, buffer))
return NULL;
if (mu_address_get_email (addr, 1, buffer, sizeof (buffer), NULL))
if (mu_address_aget_email (addr, 1, &ptr))
{
mu_address_destroy (&addr);
return NULL;
}
mu_address_destroy (&addr);
return strdup (buffer);
return buffer;
}
static int
......
......@@ -110,15 +110,15 @@ alias_destroy (const char *name)
static void
recursive_alias_expand (char *name, mu_list_t exlist, mu_list_t origlist)
recursive_alias_expand (const char *name, mu_list_t exlist, mu_list_t origlist)
{
alias_t al;
mu_iterator_t itr;
if ((al = alias_lookup (name)) == NULL)
{
if (mu_list_locate (exlist, name, NULL) == MU_ERR_NOENT)
mu_list_append (exlist, name);
if (mu_list_locate (exlist, (void*)name, NULL) == MU_ERR_NOENT)
mu_list_append (exlist, (void*)name);
return;
}
......@@ -147,7 +147,7 @@ string_comp (const void *item, const void *value)
}
char *
alias_expand (char *name)
alias_expand (const char *name)
{
alias_t al;
mu_list_t list;
......
......@@ -77,7 +77,7 @@ mail_set_my_name (char *name)
}
int
mail_is_my_name (char *name)
mail_is_my_name (const char *name)
{
if (strchr(name, '@') == NULL && strcasecmp (name, my_name) == 0)
return 1;
......
......@@ -44,9 +44,9 @@ mail_from0 (msgset_t *mspec, mu_message_t msg, void *data)
{
char name[128];
size_t len;
char *email;
const char *email;
if (mu_address_aget_email (address, 1, &email) == 0)
if (mu_address_sget_email (address, 1, &email) == 0)
{
if (util_getenv (NULL, "showto", Mail_env_boolean, 0) == 0
&& mail_is_my_name (email))
......@@ -64,7 +64,6 @@ mail_from0 (msgset_t *mspec, mu_message_t msg, void *data)
free (tmp);
}
}
free (email);
}
len = strlen (from) + 1;
......
......@@ -248,7 +248,7 @@ extern void free_env_headers (compose_env_t *env);
/*extern void print_message (mu_message_t mesg, char *prefix, int all_headers, FILE *file);*/
extern int mail_mbox_commit (void);
extern int mail_is_my_name (char *name);
extern int mail_is_my_name (const char *name);
extern void mail_set_my_name (char *name);
extern char *mail_whoami (void);
extern int mail_header_is_visible (char *str);
......@@ -343,7 +343,7 @@ extern char *util_folder_path (const char *name);
extern char *util_get_sender (int msgno, int strip);
extern void util_slist_print (mu_list_t list, int nl);
extern int util_slist_lookup (mu_list_t list, char *str);
extern int util_slist_lookup (mu_list_t list, const char *str);
extern void util_slist_add (mu_list_t *list, char *value);
extern void util_slist_remove (mu_list_t *list, char *value);
extern void util_slist_destroy (mu_list_t *list);
......@@ -381,7 +381,7 @@ extern int ml_reread (const char *prompt, char **text);
extern char *ml_readline (char *prompt);
extern char *ml_readline_with_intr (char *prompt);
extern char *alias_expand (char *name);
extern char *alias_expand (const char *name);
extern void alias_destroy (const char *name);
typedef struct alias_iterator *alias_iterator_t;
......@@ -404,8 +404,8 @@ extern void var_iterate_end (var_iterator_t *itr);
#define COMPOSE_SINGLE_LINE 2
void compose_init (compose_env_t *env);
int compose_header_set (compose_env_t *env, char *name,
char *value, int replace);
int compose_header_set (compose_env_t *env, const char *name,
const char *value, int replace);
char *compose_header_get (compose_env_t *env, char *name, char *defval);
void compose_destroy (compose_env_t *env);
......
......@@ -70,7 +70,6 @@ reply0 (msgset_t *mspec, mu_message_t msg, void *data)
mu_address_t addr = NULL;
size_t i, count = 0;
char buf[512];
if (mu_header_aget_value (hdr, MU_HEADER_TO, &str) == 0)
{
......@@ -82,11 +81,13 @@ reply0 (msgset_t *mspec, mu_message_t msg, void *data)
/* Make sure we do not include our alternate names */
for (i = 1; i <= count; i++)
{
mu_address_get_email (addr, i, buf, sizeof (buf), NULL);
const char *email;
if (mu_address_sget_email (addr, i, &email) || email == NULL)
continue;
if ((util_getenv (NULL, "metoo", Mail_env_boolean, 0) == 0)
|| !mail_is_my_name (buf))
|| !mail_is_my_name (email))
compose_header_set (&env, MU_HEADER_TO,
buf,
email,
COMPOSE_SINGLE_LINE);
}
......
......@@ -216,7 +216,8 @@ compose_init (compose_env_t * env)
}
int
compose_header_set (compose_env_t * env, char *name, char *value, int mode)
compose_header_set (compose_env_t * env, const char *name,
const char *value, int mode)
{
int status;
char *old_value;
......
......@@ -868,7 +868,7 @@ util_slist_print (mu_list_t list, int nl)
}
int
util_slist_lookup (mu_list_t list, char *str)
util_slist_lookup (mu_list_t list, const char *str)
{
mu_iterator_t itr;
char *name;
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2001, 2004, 2005,
2007 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -60,15 +61,15 @@ struct _msg_info
mu_message_t msg;
int ioffset;
int ooffset;
mu_stream_t stream; /* output file/decoding stream for saving attachment */
mu_stream_t fstream; /* output file stream for saving attachment */
mu_stream_t stream; /* output file/decoding stream for saving attachment */
mu_stream_t fstream; /* output file stream for saving attachment */
};
#define MSG_HDR "Content-Type: %s; name=%s\nContent-Transfer-Encoding: %s\nContent-Disposition: attachment; filename=%s\n\n"
int
mu_message_create_attachment (const char *content_type, const char *encoding,
const char *filename, mu_message_t * newmsg)
const char *filename, mu_message_t * newmsg)
{
mu_header_t hdr;
mu_body_t body;
......@@ -142,8 +143,8 @@ mu_message_create_attachment (const char *content_type, const char *encoding,
static int
_attachment_setup (struct _msg_info **info, mu_message_t msg, mu_stream_t * stream,
void **data)
_attachment_setup (struct _msg_info **info, mu_message_t msg,
mu_stream_t * stream, void **data)
{
int sfl, ret;
mu_body_t body;
......@@ -230,53 +231,8 @@ _header_get_param (char *field_body, const char *param, size_t * len)
return NULL;
}
#if 0
int
mu_message_get_attachment_name (mu_message_t msg, char *name, size_t bufsz, size_t *sz)
{
char *pTmp, *fname = NULL;
mu_header_t hdr;
int ret = EINVAL;
size_t size = 0;
if (filename != NULL && (ret = mu_message_get_header (msg, &hdr)) == 0)
{
*filename = NULL;
mu_header_get_value (hdr, "Content-Disposition", NULL, 0, &size);
if (size)
{
if ((pTmp = alloca (size + 1)) == NULL)
ret = ENOMEM;
mu_header_get_value (hdr, "Content-Disposition", pTmp, size + 1, 0);
if (strstr (pTmp, "attachment") != NULL)
fname = _header_get_param (pTmp, "filename", &size);
}
if (fname == NULL)
{
size = 0;
mu_header_get_value (hdr, "Content-Type", NULL, 0, &size);
if (size)
{
if ((pTmp = alloca (size + 1)) == NULL)
ret = ENOMEM;
mu_header_get_value (hdr, "Content-Type", pTmp, size + 1, 0);
fname = _header_get_param (pTmp, "name", &size);
}
}
if (fname)
{
fname[size] = '\0';
if ((*filename = strdup (fname)) == NULL)
ret = ENOMEM;
}
else
ret = MU_ERR_NOENT;
}
return ret;
}
#endif
int mu_message_aget_attachment_name(mu_message_t msg, char** name)
mu_message_aget_attachment_name(mu_message_t msg, char **name)
{
size_t sz = 0;
int ret = 0;
......@@ -299,7 +255,8 @@ int mu_message_aget_attachment_name(mu_message_t msg, char** name)
}
int
mu_message_get_attachment_name (mu_message_t msg, char *buf, size_t bufsz, size_t *sz)
mu_message_get_attachment_name (mu_message_t msg, char *buf, size_t bufsz,
size_t *sz)
{
int ret = EINVAL;
mu_header_t hdr;
......@@ -360,7 +317,8 @@ mu_message_get_attachment_name (mu_message_t msg, char *buf, size_t bufsz, size_
}
int
mu_message_save_attachment (mu_message_t msg, const char *filename, void **data)
mu_message_save_attachment (mu_message_t msg, const char *filename,
void **data)
{
mu_stream_t istream;
struct _msg_info *info = NULL;
......
......@@ -354,7 +354,7 @@ mu_set_user_email (const char *candidate)
mu_address_t addr = NULL;
size_t emailno = 0;
char *email = NULL;
char *domain = NULL;
const char *domain = NULL;
if ((err = mu_address_create (&addr, candidate)) != 0)
return err;
......@@ -376,9 +376,8 @@ mu_set_user_email (const char *candidate)
mu_user_email = email;
mu_address_aget_domain (addr, 1, &domain);
mu_set_user_email_domain (domain);
free (domain);
if ((err = mu_address_sget_domain (addr, 1, &domain)) == 0)
mu_set_user_email_domain (domain);
cleanup:
mu_address_destroy (&addr);
......@@ -391,7 +390,7 @@ static char *mu_user_email_domain = 0;
int
mu_set_user_email_domain (const char *domain)
{
char* d = NULL;
char *d = NULL;
if (!domain)
return EINVAL;
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2004, 2005,
2006 Free Software Foundation, Inc.
2006, 2007 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -201,9 +201,9 @@ sendmail_send_message (mu_mailer_t mailer, mu_message_t msg, mu_address_t from,
{
int tunnel[2];
int argc = 0;
char **argvec = NULL;
const char **argvec = NULL;
size_t tocount = 0;
char *emailfrom = NULL;
const char *emailfrom = NULL;
/* Count the length of the arg vec: */
......@@ -214,7 +214,7 @@ sendmail_send_message (mu_mailer_t mailer, mu_message_t msg, mu_address_t from,
if (from)
{
if ((status = mu_address_aget_email (from, 1, &emailfrom)) != 0)
if ((status = mu_address_sget_email (from, 1, &emailfrom)) != 0)
goto OPEN_STATE_CLEANUP;
if (!emailfrom)
......@@ -253,34 +253,18 @@ sendmail_send_message (mu_mailer_t mailer, mu_message_t msg, mu_address_t from,
argc = 0;
if ((argvec[argc++] = strdup (sendmail->path)) == 0)
{
status = ENOMEM;
goto OPEN_STATE_CLEANUP;
}
argvec[argc++] = sendmail->path;
argvec[argc++] = "-oi";
if ((argvec[argc++] = strdup ("-oi")) == 0)
{
status = ENOMEM;
goto OPEN_STATE_CLEANUP;
}
if (from)
{
if ((argvec[argc++] = strdup ("-f")) == 0)
{
status = ENOMEM;
goto OPEN_STATE_CLEANUP;
}
argvec[argc++] = "-f";
argvec[argc++] = emailfrom;
}
if (!to || mailer_property_is_set (mailer, "READ_RECIPIENTS"))
{
if ((argvec[argc++] = strdup ("-t")) == 0)
{
status = ENOMEM;
goto OPEN_STATE_CLEANUP;
}
argvec[argc++] = "-t";
}
else
{
......@@ -291,8 +275,8 @@ sendmail_send_message (mu_mailer_t mailer, mu_message_t msg, mu_address_t from,
for (; i <= count; i++)
{
char *email = 0;
if ((status = mu_address_aget_email (to, i, &email)) != 0)
const char *email;
if ((status = mu_address_sget_email (to, i, &email)) != 0)
goto OPEN_STATE_CLEANUP;
if (!email)
{
......@@ -322,7 +306,7 @@ sendmail_send_message (mu_mailer_t mailer, mu_message_t msg, mu_address_t from,
SCLOSE (STDERR_FILENO, tunnel);
close (tunnel[1]);
dup2 (tunnel[0], STDIN_FILENO);
execv (sendmail->path, argvec);
execv (sendmail->path, (char**) argvec);
exit (errno);
}
else if (sendmail->pid == -1)
......@@ -345,7 +329,6 @@ sendmail_send_message (mu_mailer_t mailer, mu_message_t msg, mu_address_t from,
for (argc = 0; argvec && argvec[argc]; argc++)
{
MAILER_DEBUG1 (mailer, MU_DEBUG_TRACE, " %s", argvec[argc]);
free (argvec[argc]);
}
MAILER_DEBUG0 (mailer, MU_DEBUG_TRACE, "\n");
free (argvec);
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2001, 2004, 2005,
2006 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -95,7 +96,7 @@ struct _smtp
int extended;
char *mail_from;
const char *mail_from;
mu_address_t rcpt_to; /* Destroy this if not the same as argto below. */
mu_address_t rcpt_bcc;
size_t rcpt_to_count;
......@@ -140,10 +141,7 @@ CLEAR_STATE (smtp_t smtp)
smtp->extended = 0;
if (smtp->mail_from)
{
free (smtp->mail_from);
smtp->mail_from = NULL;
}
smtp->mail_from = NULL;
if (smtp->rcpt_to != smtp->argto)
mu_address_destroy (&smtp->rcpt_to);
......@@ -570,7 +568,7 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom
smtp->argfrom = argfrom;
smtp->argto = argto;
status = mu_address_aget_email (smtp->argfrom, 1, &smtp->mail_from);
status = mu_address_sget_email (smtp->argfrom, 1, &smtp->mail_from);
CHECK_ERROR (smtp, status);
status = _smtp_set_rcpt (smtp, smtp->argmsg, smtp->argto);
......@@ -626,11 +624,11 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom
ENV_RCPT:
{
mu_address_t addr = smtp->rcpt_to;
char *to = NULL;
const char *to = NULL;
if (smtp->bccing)
addr = smtp->rcpt_bcc;
status = mu_address_aget_email (addr, smtp->rcpt_index, &to);
status = mu_address_sget_email (addr, smtp->rcpt_index, &to);
CHECK_ERROR (smtp, status);
......@@ -643,8 +641,6 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom
status = smtp_writeline (smtp, "RCPT TO: <%s>\r\n", to);
free (to);
CHECK_ERROR (smtp, status);
smtp->state = SMTP_RCPT_TO;
......
......@@ -309,7 +309,7 @@ void mh_expand_aliases (mu_message_t msg, mu_address_t *addr_to,
mu_address_t *addr_cc,
mu_address_t *addr_bcc);
int mh_is_my_name (char *name);
int mh_is_my_name (const char *name);
char * mh_my_email (void);
int mh_iterate (mu_mailbox_t mbox, mh_msgset_t *msgset,
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2003,
2005, 2006 Free Software Foundation, Inc.
2005, 2006, 2007 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -41,7 +41,7 @@ strobj_free (strobj_t *obj)
}
void
strobj_create (strobj_t *lvalue, char *str)
strobj_create (strobj_t *lvalue, const char *str)
{
if (!str)
{
......@@ -366,11 +366,10 @@ addr_cmp (void *item, void *data)
mu_address_get_count (a, &count);
for (i = 1; rc == 0 && i <= count; i++)
{
char *str;
if (mu_address_aget_email (a, i, &str))
const char *str;
if (mu_address_sget_email (a, i, &str))
continue;
rc = mu_address_contains_email (b, str);
free (str);
}
return rc;
}
......@@ -1475,8 +1474,7 @@ static void
builtin_addr (struct mh_machine *mach)
{
mu_address_t addr;
size_t n;
char buf[80];
const char *str;
int rc;
rc = mu_address_create (&addr, strobj_ptr (&mach->arg_str));
......@@ -1484,8 +1482,8 @@ builtin_addr (struct mh_machine *mach)
if (rc)
return;
if (mu_address_get_email (addr, 1, buf, sizeof buf, &n) == 0)
strobj_create (&mach->arg_str, buf);
if (mu_address_sget_email (addr, 1, &str) == 0)
strobj_create (&mach->arg_str, str);
mu_address_destroy (&addr);
}
......@@ -1494,8 +1492,7 @@ static void
builtin_pers (struct mh_machine *mach)
{
mu_address_t addr;
size_t n;
char buf[80];
const char *str;
int rc;
rc = mu_address_create (&addr, strobj_ptr (&mach->arg_str));
......@@ -1503,11 +1500,10 @@ builtin_pers (struct mh_machine *mach)
if (rc)
return;
if (mu_address_get_personal (addr, 1, buf, sizeof buf, &n) == 0
&& n > 1)
if (mu_address_sget_personal (addr, 1, &str) == 0 && str)
{
char *p;
asprintf (&p, "\"%s\"", buf);
asprintf (&p, "\"%s\"", str);
strobj_create (&mach->arg_str, p);
free (p);
}
......@@ -1520,8 +1516,7 @@ static void
builtin_note (struct mh_machine *mach)
{
mu_address_t addr;
size_t n;
char buf[80];
const char *str;
int rc;
rc = mu_address_create (&addr, strobj_ptr (&mach->arg_str));
......@@ -1529,8 +1524,8 @@ builtin_note (struct mh_machine *mach)
if (rc)
return;
if (mu_address_get_comments (addr, 1, buf, sizeof buf, &n) == 0)
strobj_create (&mach->arg_str, buf);
if (mu_address_sget_comments (addr, 1, &str) == 0)
strobj_create (&mach->arg_str, str);
mu_address_destroy (&addr);
}
......@@ -1539,8 +1534,7 @@ static void
builtin_mbox (struct mh_machine *mach)
{
mu_address_t addr;
size_t n;
char buf[80];
char *str;
int rc;
rc = mu_address_create (&addr, strobj_ptr (&mach->arg_str));
......@@ -1548,12 +1542,13 @@ builtin_mbox (struct mh_machine *mach)
if (rc)
return;
if (mu_address_get_email (addr, 1, buf, sizeof buf, &n) == 0)
if (mu_address_aget_email (addr, 1, &str) == 0)
{
char *p = strchr (buf, '@');
char *p = strchr (str, '@');
if (p)
*p = 0;
strobj_create (&mach->arg_str, p);
free (str);
}
mu_address_destroy (&addr);
}
......@@ -1563,15 +1558,14 @@ static void
builtin_mymbox (struct mh_machine *mach)
{
mu_address_t addr;
size_t n;
char buf[80];
const char *str;
mach->arg_num = 0;
if (mu_address_create (&addr, strobj_ptr (&mach->arg_str)))
return;
if (mu_address_get_email (addr, 1, buf, sizeof buf, &n) == 0)
mach->arg_num = mh_is_my_name (buf);
if (mu_address_sget_email (addr, 1, &str) == 0 && str)
mach->arg_num = mh_is_my_name (str);
mu_address_destroy (&addr);
}
......@@ -1580,8 +1574,7 @@ static void
builtin_host (struct mh_machine *mach)
{
mu_address_t addr;
size_t n;
char buf[80];
char *str;
int rc;
rc = mu_address_create (&addr, strobj_ptr (&mach->arg_str));
......@@ -1589,11 +1582,12 @@ builtin_host (struct mh_machine *mach)
if (rc)
return;
if (mu_address_get_email (addr, 1, buf, sizeof buf, &n) == 0)
if (mu_address_aget_email (addr, 1, &str) == 0)
{
char *p = strchr (buf, '@');
char *p = strchr (str, '@');
if (p)
strobj_create (&mach->arg_str, p+1);
free (str);
}
mu_address_destroy (&addr);
}
......@@ -1603,17 +1597,15 @@ static void
builtin_nohost (struct mh_machine *mach)
{
mu_address_t addr;
size_t n;
char buf[80];
int rc;
const char *str;
rc = mu_address_create (&addr, strobj_ptr (&mach->arg_str));
int rc = mu_address_create (&addr, strobj_ptr (&mach->arg_str));
strobj_free (&mach->arg_str);
if (rc)
return;
if (mu_address_get_email (addr, 1, buf, sizeof buf, &n) == 0)
mach->arg_num = strchr (buf, '@') != NULL;
if (mu_address_sget_email (addr, 1, &str) == 0 && str)
mach->arg_num = strchr (str, '@') != NULL;
else
mach->arg_num = 0;
mu_address_destroy (&addr);
......@@ -1625,20 +1617,19 @@ static void
builtin_type (struct mh_machine *mach)
{
mu_address_t addr;
size_t n;
char buf[80];
int rc;
const char *str;
rc = mu_address_create (&addr, strobj_ptr (&mach->arg_str));
strobj_free (&mach->arg_str);
if (rc)
return;
if (mu_address_get_email (addr, 1, buf, sizeof buf, &n) == 0)
if (mu_address_sget_email (addr, 1, &str) == 0 && str)
{
if (strchr (buf, '@'))
if (strchr (str, '@'))
mach->arg_num = 1;
else if (strchr (buf, '@'))
else if (strchr (str, '!'))
mach->arg_num = -1;
else
mach->arg_num = 0; /* assume local */
......@@ -1653,16 +1644,13 @@ static void
builtin_path (struct mh_machine *mach)
{
mu_address_t addr;
size_t n;
char buf[80];
int rc;
rc = mu_address_create (&addr, strobj_ptr (&mach->arg_str));
const char *str;
int rc = mu_address_create (&addr, strobj_ptr (&mach->arg_str));
strobj_free (&mach->arg_str);
if (rc)
return;
if (mu_address_get_route (addr, 1, buf, sizeof buf, &n))
strobj_create (&mach->arg_str, buf);
if (mu_address_sget_route (addr, 1, &str))
strobj_create (&mach->arg_str, str);
mu_address_destroy (&addr);
}
......@@ -1691,7 +1679,7 @@ builtin_formataddr (struct mh_machine *mach)
size_t size;
int i;
size_t num;
char *buf;
const char *buf;
if (strobj_len (&mach->reg_str) == 0)
dest = NULL;
......@@ -1707,7 +1695,7 @@ builtin_formataddr (struct mh_machine *mach)
mu_address_get_count (addr, &num);
for (i = 1; i <= num; i++)
{
if (mu_address_aget_email (addr, i, &buf) == 0)
if (mu_address_sget_email (addr, i, &buf) == 0)
{
if ((rcpt_mask & RCPT_ME) || !mh_is_my_name (buf))
{
......@@ -1721,7 +1709,6 @@ builtin_formataddr (struct mh_machine *mach)
else
mu_address_destroy (&subaddr);
}
free (buf);
}
}
......
......@@ -57,7 +57,7 @@ struct mh_machine
};
void strobj_free (strobj_t *obj);
void strobj_create (strobj_t *lvalue, char *str);
void strobj_create (strobj_t *lvalue, const char *str);
void strobj_set (strobj_t *lvalue, char *str);
void strobj_assign (strobj_t *lvalue, strobj_t *rvalue);
void strobj_copy (strobj_t *lvalue, strobj_t *rvalue);
......
......@@ -160,7 +160,7 @@ emailcmp (char *pattern, char *name)
}
int
mh_is_my_name (char *name)
mh_is_my_name (const char *name)
{
char *pname, *p;
int rc = 0;
......