summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2007-06-26 13:57:04 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2007-06-26 13:57:04 +0000
commit1ccdf8eba56f46be5cc8bde04bf9f4c705148a2f (patch)
treeeb89da5052fcd6e20e45954b36add008ad0d1c60
parent23e39709d95eb384037de68511d83672a21daf70 (diff)
downloadmailutils-1ccdf8eba56f46be5cc8bde04bf9f4c705148a2f.tar.gz
mailutils-1ccdf8eba56f46be5cc8bde04bf9f4c705148a2f.tar.bz2
Prefer mu_header_sgetwhere possible. Remove obsolete header calls.
-rw-r--r--examples/mimetest.c41
-rw-r--r--libproto/imap/mbox.c86
-rw-r--r--libproto/mbox/mbox.c30
-rw-r--r--libsieve/actions.c25
-rw-r--r--mail.local/mailquota.c4
-rw-r--r--mail/decode.c17
-rw-r--r--mail/escape.c13
-rw-r--r--mail/mail.h4
-rw-r--r--mail/print.c14
-rw-r--r--mail/retain.c7
-rw-r--r--mail/send.c4
-rw-r--r--mailbox/sendmail.c2
12 files changed, 73 insertions, 174 deletions
diff --git a/examples/mimetest.c b/examples/mimetest.c
index 706e2af6d..d976ab666 100644
--- a/examples/mimetest.c
+++ b/examples/mimetest.c
@@ -1,5 +1,5 @@
/* 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
@@ -29,8 +29,8 @@
void message_display_parts(mu_message_t msg, int indent);
-char from[256];
-char subject[256];
+const char *from;
+const char *subject;
int print_attachments;
int indent_level = 4;
@@ -120,9 +120,10 @@ main (int argc, char **argv)
CATCH (mu_message_size (msg, &msize));
CATCH (mu_message_lines (msg, &nlines));
CATCH (mu_message_get_header (msg, &hdr));
- mu_header_get_value (hdr, MU_HEADER_FROM, from, sizeof (from), NULL);
- mu_header_get_value (hdr, MU_HEADER_SUBJECT, subject, sizeof (subject),
- NULL);
+ if (mu_header_sget_value (hdr, MU_HEADER_FROM, &from))
+ from = "";
+ if (mu_header_sget_value (hdr, MU_HEADER_SUBJECT, &subject))
+ subject = "";
printf ("Message: %lu\n", (unsigned long) i);
printf ("From: %s\n", from);
printf ("Subject: %s\n", subject);
@@ -170,8 +171,8 @@ message_display_parts (mu_message_t msg, int indent)
size_t nparts, nsubparts;
mu_message_t part;
mu_header_t hdr;
- char type[256];
- char encoding[256];
+ const char *type;
+ const char *encoding;
mu_stream_t str;
mu_body_t body;
int offset, ismulti;
@@ -189,15 +190,22 @@ message_display_parts (mu_message_t msg, int indent)
its own that can have other subparts(recursive). */
for (j = 1; j <= nparts; j++)
{
+ int status;
CATCH (mu_message_get_part (msg, j, &part));
CATCH (mu_message_get_header (part, &hdr));
- mu_header_get_value (hdr, MU_HEADER_CONTENT_TYPE, type, sizeof (type),
- NULL);
+ status = mu_header_sget_value (hdr, MU_HEADER_CONTENT_TYPE, &type);
+ if (status == MU_ERR_NOENT)
+ type = "";
+ else if (status != 0)
+ {
+ type = "";
+ mu_error ("Cannot get header value: %s", mu_strerror (status));
+ }
printf ("%*.*sType of part %d = %s\n", indent, indent, "", j, type);
print_message_part_sizes (part, indent);
- encoding[0] = '\0';
- mu_header_get_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING, encoding,
- sizeof (encoding), NULL);
+ if (mu_header_sget_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING,
+ &encoding))
+ encoding = "";
ismulti = 0;
if ((type[0]
&& strncasecmp (type, "message/rfc822", strlen (type)) == 0)
@@ -207,9 +215,10 @@ message_display_parts (mu_message_t msg, int indent)
CATCH (mu_message_unencapsulate (part, &part, NULL));
CATCH (mu_message_get_header (part, &hdr));
- mu_header_get_value (hdr, MU_HEADER_FROM, from, sizeof (from), NULL);
- mu_header_get_value (hdr, MU_HEADER_SUBJECT, subject, sizeof (subject),
- NULL);
+ if (mu_header_sget_value (hdr, MU_HEADER_FROM, &from))
+ from = "";
+ if (mu_header_sget_value (hdr, MU_HEADER_SUBJECT, &subject))
+ subject = "";
printf ("%*.*sEncapsulated message : %s\t%s\n",
indent, indent, "", from, subject);
printf ("%*.*sBegin\n", indent, indent, "");
diff --git a/libproto/imap/mbox.c b/libproto/imap/mbox.c
index dec973e97..1a2867e71 100644
--- a/libproto/imap/mbox.c
+++ b/libproto/imap/mbox.c
@@ -100,7 +100,6 @@ static int imap_attr_unset_flags (mu_attribute_t, int);
/* mu_header_t API. */
static int imap_header_read (mu_header_t, char*, size_t, mu_off_t, size_t *);
-static int imap_header_get_value (mu_header_t, const char*, char *, size_t, size_t *);
/* mu_body_t API. */
static int imap_body_read (mu_stream_t, char *, size_t, mu_off_t, size_t *);
@@ -545,7 +544,6 @@ imap_get_message0 (msg_imap_t msg_imap, mu_message_t *pmsg)
return status;
}
mu_header_set_fill (header, imap_header_read, msg);
- mu_header_set_get_value (header, imap_header_get_value, msg);
mu_message_set_header (msg, header, msg_imap);
}
@@ -1451,7 +1449,6 @@ imap_get_part (mu_message_t msg, size_t partno, mu_message_t *pmsg)
{
mu_header_t header;
mu_message_get_header (message, &header);
- mu_header_set_get_value (header, NULL, message);
mu_message_set_stream (message, NULL, msg_imap->parts[partno - 1]);
/* mu_message_set_size (message, NULL, msg_imap->parts[partno - 1]); */
msg_imap->parts[partno - 1]->message = message;
@@ -1721,89 +1718,6 @@ imap_attr_unset_flags (mu_attribute_t attribute, int flag)
/* Header. */
static int
-imap_header_get_value (mu_header_t header, const char *field, char * buffer,
- size_t buflen, size_t *plen)
-{
- mu_message_t msg = mu_header_get_owner (header);
- msg_imap_t msg_imap = mu_message_get_owner (msg);
- m_imap_t m_imap = msg_imap->m_imap;
- f_imap_t f_imap = m_imap->f_imap;
- int status;
- size_t len = 0;
- char *value;
-
- /* Select first. */
- status = imap_messages_count (m_imap->mailbox, NULL);
- if (status != 0)
- return status;
-
- /* Hack, if buffer == NULL they want to know how big is the field value,
- Unfortunately IMAP does not say, so we take a guess hoping that the
- value will not be over 1024. */
- if (buffer == NULL || buflen == 0)
- len = 1024;
- else
- len = strlen (field) + buflen + 4;
-
- if (f_imap->state == IMAP_NO_STATE)
- {
- /* Select first. */
- status = imap_messages_count (m_imap->mailbox, NULL);
- if (status != 0)
- return status;
- status = imap_writeline (f_imap,
- "g%s FETCH %s BODY.PEEK[HEADER.FIELDS (%s)]<0.%s>\r\n",
- mu_umaxtostr (0, f_imap->seq++),
- mu_umaxtostr (1, msg_imap->num),
- field,
- mu_umaxtostr (2, len));
- CHECK_ERROR (f_imap, status);
- MAILBOX_DEBUG0 (m_imap->mailbox, MU_DEBUG_PROT, f_imap->buffer);
- f_imap->state = IMAP_FETCH;
-
- }
-
- value = calloc (len, sizeof (*value));
- status = fetch_operation (f_imap, msg_imap, value, len, &len);
- if (status == 0)
- {
- char *colon;
- /* The field-matching is case-insensitive. In all cases, the
- delimiting newline between the header and the body is always
- included. Nuke it */
- if (len)
- value[len - 1] = '\0';
-
- /* Move pass the field-name. */
- colon = strchr (value, ':');
- if (colon)
- {
- colon++;
- if (*colon == ' ')
- colon++;
- }
- else
- colon = value;
-
- while (*colon && colon[strlen (colon) - 1] == '\n')
- colon[strlen (colon) - 1] = '\0';
-
- if (buffer && buflen)
- {
- strncpy (buffer, colon, buflen);
- buffer[buflen - 1] = '\0';
- }
- len = strlen (buffer);
- if (plen)
- *plen = len;
- if (len == 0)
- status = MU_ERR_NOENT;
- }
- free (value);
- return status;
-}
-
-static int
imap_header_read (mu_header_t header, char *buffer,
size_t buflen, mu_off_t offset,
size_t *plen)
diff --git a/libproto/mbox/mbox.c b/libproto/mbox/mbox.c
index 33431cbad..9e49d342d 100644
--- a/libproto/mbox/mbox.c
+++ b/libproto/mbox/mbox.c
@@ -63,8 +63,6 @@ static int mbox_readstream (mbox_message_t, char *, size_t,
mu_off_t, size_t *, int, mu_off_t, mu_off_t);
static int mbox_stream_size (mu_stream_t stream, mu_off_t *psize);
-static int mbox_header_size (mu_header_t, size_t *);
-static int mbox_header_lines (mu_header_t, size_t *);
static int mbox_body_size (mu_body_t, size_t *);
static int mbox_body_lines (mu_body_t, size_t *);
static int mbox_envelope_sender (mu_envelope_t, char *, size_t, size_t *);
@@ -894,7 +892,7 @@ mbox_readstream (mbox_message_t mum, char *buffer, size_t buflen,
start + off, &nread);
else
status = mu_stream_read (mum->mud->mailbox->stream, buffer, nread,
- start + off, &nread);
+ start + off, &nread);
}
}
mu_monitor_unlock (mum->mud->mailbox->monitor);
@@ -918,30 +916,6 @@ mbox_header_fill (mu_header_t header, char *buffer, size_t len,
}
static int
-mbox_header_size (mu_header_t header, size_t *psize)
-{
- mu_message_t msg = mu_header_get_owner (header);
- mbox_message_t mum = mu_message_get_owner (msg);
- if (mum == NULL)
- return EINVAL;
- if (psize)
- *psize = mum->body - mum->header_from_end;
- return 0;
-}
-
-static int
-mbox_header_lines (mu_header_t header, size_t *plines)
-{
- mu_message_t msg = mu_header_get_owner (header);
- mbox_message_t mum = mu_message_get_owner (msg);
- if (mum == NULL)
- return EINVAL;
- if (plines)
- *plines = mum->header_lines;
- return 0;
-}
-
-static int
mbox_body_size (mu_body_t body, size_t *psize)
{
mu_message_t msg = mu_body_get_owner (body);
@@ -1120,8 +1094,6 @@ mbox_get_message (mu_mailbox_t mailbox, size_t msgno, mu_message_t *pmsg)
return status;
}
mu_header_set_fill (header, mbox_header_fill, msg);
- mu_header_set_size (header, mbox_header_size, msg);
- mu_header_set_lines (header, mbox_header_lines, msg);
mu_message_set_header (msg, header, mum);
}
diff --git a/libsieve/actions.c b/libsieve/actions.c
index e241447e6..83fb9569c 100644
--- a/libsieve/actions.c
+++ b/libsieve/actions.c
@@ -1,6 +1,6 @@
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 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
@@ -146,8 +146,9 @@ mime_create_reason (mu_mime_t mime, mu_message_t msg, const char *text)
mu_body_t body;
mu_header_t hdr;
char datestr[80];
- static char *content_header = "Content-Type: text/plain;charset=" MU_SIEVE_CHARSET "\n"
- "Content-Transfer-Encoding: 8bit\n";
+ static char *content_header =
+ "Content-Type: text/plain;charset=" MU_SIEVE_CHARSET "\n"
+ "Content-Transfer-Encoding: 8bit\n";
mu_message_create (&newmsg, NULL);
mu_message_get_body (newmsg, &body);
@@ -160,7 +161,7 @@ mime_create_reason (mu_mime_t mime, mu_message_t msg, const char *text)
mu_sieve_get_message_sender (msg, &sender);
mu_stream_printf (stream, &off,
- "\nThe original message was received at %s from %s.\n",
+ "The original message was received at %s from %s.\n",
datestr, sender);
free (sender);
mu_stream_printf (stream, &off,
@@ -302,10 +303,10 @@ sieve_action_reject (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
if (rc)
{
mu_sieve_error (mach,
- _("%d: cannot create sender address <%s>: %s"),
- mu_sieve_get_message_num (mach),
- mu_sieve_get_daemon_email (mach),
- mu_strerror (rc));
+ _("%d: cannot create sender address <%s>: %s"),
+ mu_sieve_get_message_num (mach),
+ mu_sieve_get_daemon_email (mach),
+ mu_strerror (rc));
goto end;
}
@@ -316,10 +317,10 @@ sieve_action_reject (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
mu_mailer_get_url (mailer, &url);
mu_sieve_error (mach,
- _("%d: cannot open mailer %s: %s"),
- mu_sieve_get_message_num (mach),
- mu_url_to_string (url),
- mu_strerror (rc));
+ _("%d: cannot open mailer %s: %s"),
+ mu_sieve_get_message_num (mach),
+ mu_url_to_string (url),
+ mu_strerror (rc));
goto end;
}
diff --git a/mail.local/mailquota.c b/mail.local/mailquota.c
index e372b29dc..86160ee6d 100644
--- a/mail.local/mailquota.c
+++ b/mail.local/mailquota.c
@@ -1,6 +1,6 @@
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2004,
- 2005 Free Software Foundation, Inc.
+ 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
@@ -155,7 +155,7 @@ sql_retrieve_quota (char *name, mu_off_t *quota)
char *query_str;
int rc, status;
char *tmp;
- mu_off_t n;
+ size_t n;
query_str = mu_sql_expand_query (quota_query, name);
if (!query_str)
diff --git a/mail/decode.c b/mail/decode.c
index 6108f1073..f09ac7088 100644
--- a/mail/decode.c
+++ b/mail/decode.c
@@ -1,6 +1,6 @@
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2003,
- 2005 Free Software Foundation, Inc.
+ 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
@@ -83,19 +83,20 @@ display_headers (FILE *out, mu_message_t mesg, const msgset_t *msgset ARG_UNUSED
{
size_t num = 0;
size_t i = 0;
- char buffer[512];
+ const char *sptr;
mu_message_get_header (mesg, &hdr);
mu_header_get_field_count (hdr, &num);
for (i = 1; i <= num; i++)
{
- buffer[0] = '\0';
- mu_header_get_field_name (hdr, i, buffer, sizeof(buffer), NULL);
- if (mail_header_is_visible (buffer))
+ if (mu_header_sget_field_name (hdr, i, &sptr))
+ continue;
+ if (mail_header_is_visible (sptr))
{
- fprintf (out, "%s: ", buffer);
- mu_header_get_field_value (hdr, i, buffer, sizeof(buffer), NULL);
- fprintf (out, "%s\n", buffer);
+ fprintf (out, "%s: ", sptr);
+ if (mu_header_sget_field_value (hdr, i, &sptr))
+ sptr = "";
+ fprintf (out, "%s\n", sptr);
}
}
fprintf (out, "\n");
diff --git a/mail/escape.c b/mail/escape.c
index b93635151..81fdfb1ef 100644
--- a/mail/escape.c
+++ b/mail/escape.c
@@ -1,5 +1,6 @@
/* GNU Mailutils -- a suite of utilities for electronic mail
- Copyright (C) 1999, 2001, 2002, 2005, 2006 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2001, 2002, 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
@@ -456,20 +457,20 @@ quote0 (msgset_t *mspec, mu_message_t mesg, void *data)
if (*(int*)data)
{
size_t i, num = 0;
- char buf[512];
+ const char *sptr;
mu_message_get_header (mesg, &hdr);
mu_header_get_field_count (hdr, &num);
for (i = 1; i <= num; i++)
{
- mu_header_get_field_name (hdr, i, buf, sizeof buf, NULL);
- if (mail_header_is_visible (buf))
+ mu_header_sget_field_name (hdr, i, &sptr);
+ if (mail_header_is_visible (sptr))
{
char *value;
- fprintf (ofile, "%s%s: ", prefix, buf);
- if (mu_header_aget_value (hdr, buf, &value) == 0)
+ fprintf (ofile, "%s%s: ", prefix, sptr);
+ if (mu_header_aget_value (hdr, sptr, &value) == 0)
{
int i;
char *p, *s;
diff --git a/mail/mail.h b/mail/mail.h
index dcc79cfe3..782eba224 100644
--- a/mail/mail.h
+++ b/mail/mail.h
@@ -251,8 +251,8 @@ extern int mail_mbox_commit (void);
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);
-extern int mail_header_is_unfoldable (char *str);
+extern int mail_header_is_visible (const char *str);
+extern int mail_header_is_unfoldable (const char *str);
extern int mail_mbox_close (void);
extern char *mail_expand_name (const char *name);
diff --git a/mail/print.c b/mail/print.c
index 9d9a00067..0a445ae5d 100644
--- a/mail/print.c
+++ b/mail/print.c
@@ -1,5 +1,6 @@
/* GNU Mailutils -- a suite of utilities for electronic mail
- Copyright (C) 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001, 2002, 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
@@ -61,7 +62,7 @@ mail_print_msg (msgset_t *mspec, mu_message_t mesg, void *data)
if (*(int *) data) /* print was called with a lowercase 'p' */
{
size_t i, num = 0;
- char buf[512];
+ const char *sptr;
char *tmp;
mu_message_get_header (mesg, &hdr);
@@ -69,12 +70,13 @@ mail_print_msg (msgset_t *mspec, mu_message_t mesg, void *data)
for (i = 1; i <= num; i++)
{
- mu_header_get_field_name (hdr, i, buf, sizeof buf, NULL);
- if (mail_header_is_visible (buf))
+ if (mu_header_sget_field_name (hdr, i, &sptr))
+ continue;
+ if (mail_header_is_visible (sptr))
{
- fprintf (out, "%s: ", buf);
+ fprintf (out, "%s: ", sptr);
mu_header_aget_field_value (hdr, i, &tmp);
- if (mail_header_is_unfoldable (buf))
+ if (mail_header_is_unfoldable (sptr))
mu_string_unfold (tmp, NULL);
util_rfc2047_decode (&tmp);
fprintf (out, "%s\n", tmp);
diff --git a/mail/retain.c b/mail/retain.c
index deca5498d..7b49249d6 100644
--- a/mail/retain.c
+++ b/mail/retain.c
@@ -1,5 +1,6 @@
/* GNU Mailutils -- a suite of utilities for electronic mail
- Copyright (C) 1999, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2001, 2002, 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
@@ -94,13 +95,13 @@ mail_nounfold (int argc, char **argv)
}
int
-mail_header_is_unfoldable (char *str)
+mail_header_is_unfoldable (const char *str)
{
return util_slist_lookup (unfolded_headers, str);
}
int
-mail_header_is_visible (char *str)
+mail_header_is_visible (const char *str)
{
if (retained_headers)
return util_slist_lookup (retained_headers, str);
diff --git a/mail/send.c b/mail/send.c
index e81935fe7..173ffed57 100644
--- a/mail/send.c
+++ b/mail/send.c
@@ -1,6 +1,6 @@
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2001, 2002, 2003, 2004,
- 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
@@ -366,7 +366,6 @@ mail_send0 (compose_env_t * env, int save_to)
char *escape;
fd = mu_tempfile (NULL, &filename);
-
if (fd == -1)
{
util_error (_("Cannot open temporary file"));
@@ -527,7 +526,6 @@ mail_send0 (compose_env_t * env, int save_to)
int rc;
mu_message_create (&msg, NULL);
-
mu_message_set_header (msg, env->header, NULL);
/* Fill the body. */
diff --git a/mailbox/sendmail.c b/mailbox/sendmail.c
index 0979f61e6..cac044674 100644
--- a/mailbox/sendmail.c
+++ b/mailbox/sendmail.c
@@ -359,7 +359,7 @@ sendmail_send_message (mu_mailer_t mailer, mu_message_t msg, mu_address_t from,
MAILER_DEBUG0 (mailer, MU_DEBUG_TRACE, "Sending headers...\n");
while ((status = mu_stream_readline (stream, buffer, sizeof (buffer),
- offset, &len)) == 0
+ offset, &len)) == 0
&& len != 0)
{
if (strncasecmp (buffer, MU_HEADER_FCC,

Return to:

Send suggestions and report system problems to the System administrator.