notmuch reply: Handle notmuch_message_get_header returning NULL.

This seems a rather unlikely case, (replying to a message that
disappears out from under us half way through the reply), but
notmuch_message_get_header is documented to return NULL in error
cases, so we might as well deal sanely with that (rather than just
crashing).
This commit is contained in:
Carl Worth 2010-04-24 06:33:32 -07:00
parent c87d17f28e
commit d06a34ad5d

View file

@ -201,6 +201,9 @@ add_recipients_for_string (GMimeMessage *message,
{ {
InternetAddressList *list; InternetAddressList *list;
if (recipients == NULL)
return NULL;
list = internet_address_list_parse_string (recipients); list = internet_address_list_parse_string (recipients);
if (list == NULL) if (list == NULL)
return NULL; return NULL;
@ -214,16 +217,16 @@ add_recipients_for_string (GMimeMessage *message,
static int static int
reply_to_header_is_redundant (notmuch_message_t *message) reply_to_header_is_redundant (notmuch_message_t *message)
{ {
const char *header, *addr; const char *reply_to, *to, *cc, *addr;
InternetAddressList *list; InternetAddressList *list;
InternetAddress *address; InternetAddress *address;
InternetAddressMailbox *mailbox; InternetAddressMailbox *mailbox;
header = notmuch_message_get_header (message, "reply-to"); reply_to = notmuch_message_get_header (message, "reply-to");
if (*header == '\0') if (reply_to == NULL || *reply_to == '\0')
return 0; return 0;
list = internet_address_list_parse_string (header); list = internet_address_list_parse_string (reply_to);
if (internet_address_list_length (list) != 1) if (internet_address_list_length (list) != 1)
return 0; return 0;
@ -235,8 +238,11 @@ reply_to_header_is_redundant (notmuch_message_t *message)
mailbox = INTERNET_ADDRESS_MAILBOX (address); mailbox = INTERNET_ADDRESS_MAILBOX (address);
addr = internet_address_mailbox_get_addr (mailbox); addr = internet_address_mailbox_get_addr (mailbox);
if (strstr (notmuch_message_get_header (message, "to"), addr) != 0 || to = notmuch_message_get_header (message, "to");
strstr (notmuch_message_get_header (message, "cc"), addr) != 0) cc = notmuch_message_get_header (message, "cc");
if ((to && strstr (to, addr) != 0) ||
(cc && strstr (cc, addr) != 0))
{ {
return 1; return 1;
} }
@ -314,6 +320,9 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message
size_t i,other_len; size_t i,other_len;
received = notmuch_message_get_header (message, "received"); received = notmuch_message_get_header (message, "received");
if (received == NULL)
return NULL;
by = strstr (received, " by "); by = strstr (received, " by ");
if (by && *(by+4)) { if (by && *(by+4)) {
/* sadly, the format of Received: headers is a bit inconsistent, /* sadly, the format of Received: headers is a bit inconsistent,
@ -387,9 +396,11 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
} }
subject = notmuch_message_get_header (message, "subject"); subject = notmuch_message_get_header (message, "subject");
if (strncasecmp (subject, "Re:", 3)) if (subject) {
subject = talloc_asprintf (ctx, "Re: %s", subject); if (strncasecmp (subject, "Re:", 3))
g_mime_message_set_subject (reply, subject); subject = talloc_asprintf (ctx, "Re: %s", subject);
g_mime_message_set_subject (reply, subject);
}
from_addr = add_recipients_from_message (reply, config, message); from_addr = add_recipients_from_message (reply, config, message);