dovecot: mail_*() APIs changed to return int and return the actu...
dovecot at dovecot.org
dovecot at dovecot.org
Sun Aug 12 19:41:34 EEST 2007
details: http://hg.dovecot.org/dovecot/rev/eb7c9d8ece54
changeset: 6280:eb7c9d8ece54
user: Timo Sirainen <tss at iki.fi>
date: Sun Aug 12 19:40:54 2007 +0300
description:
mail_*() APIs changed to return int and return the actual data as pointer.
Changed some code to do error handling a bit better.
diffstat:
29 files changed, 761 insertions(+), 696 deletions(-)
src/deliver/deliver.c | 22 -
src/deliver/mail-send.c | 26 -
src/imap/imap-fetch-body.c | 31 -
src/imap/imap-fetch.c | 19 -
src/imap/imap-thread.c | 22 -
src/lib-storage/index/cydir/cydir-mail.c | 45 +-
src/lib-storage/index/dbox/dbox-mail.c | 91 ++---
src/lib-storage/index/index-mail-headers.c | 123 ++++---
src/lib-storage/index/index-mail.c | 412 +++++++++++++-------------
src/lib-storage/index/index-mail.h | 48 +--
src/lib-storage/index/index-search.c | 21 -
src/lib-storage/index/index-sort.c | 50 +--
src/lib-storage/index/maildir/maildir-mail.c | 140 ++++----
src/lib-storage/index/maildir/maildir-save.c | 6
src/lib-storage/index/mbox/mbox-mail.c | 98 +++---
src/lib-storage/mail-copy.c | 15
src/lib-storage/mail-storage-private.h | 43 +-
src/lib-storage/mail-storage.h | 72 ++--
src/lib-storage/mail.c | 78 ++--
src/plugins/expire/expire-plugin.c | 3
src/plugins/expire/expire-tool.c | 3
src/plugins/fts/fts-storage.c | 3
src/plugins/mail-log/mail-log-plugin.c | 17 -
src/plugins/quota/quota-count.c | 3
src/plugins/quota/quota-storage.c | 11
src/plugins/quota/quota.c | 12
src/plugins/trash/trash-plugin.c | 7
src/pop3/client.c | 5
src/pop3/commands.c | 31 -
diffs (truncated from 2765 to 300 lines):
diff -r f52e7d1402b5 -r eb7c9d8ece54 src/deliver/deliver.c
--- a/src/deliver/deliver.c Sun Aug 12 18:16:40 2007 +0300
+++ b/src/deliver/deliver.c Sun Aug 12 19:40:54 2007 +0300
@@ -152,8 +152,10 @@ int deliver_save(struct mail_namespace *
else
ret = mailbox_transaction_commit(&t, 0);
- msgid = mail_get_first_header(mail, "Message-ID");
- msgid = msgid == NULL ? "" : str_sanitize(msgid, 80);
+ if (mail_get_first_header(mail, "Message-ID", &msgid) <= 0)
+ msgid = "";
+ else
+ msgid = str_sanitize(msgid, 80);
mailbox_name = str_sanitize(mailbox_get_name(box), 80);
if (ret == 0) {
@@ -175,11 +177,11 @@ const char *deliver_get_return_address(s
struct message_address *addr;
const char *str;
- str = mail_get_first_header(mail, "Return-Path");
- addr = str == NULL ? NULL :
- message_address_parse(pool_datastack_create(),
- (const unsigned char *)str,
- strlen(str), 1, FALSE);
+ if (mail_get_first_header(mail, "Return-Path", &str) <= 0)
+ return NULL;
+ addr = message_address_parse(pool_datastack_create(),
+ (const unsigned char *)str,
+ strlen(str), 1, FALSE);
return addr == NULL || addr->mailbox == NULL || addr->domain == NULL ||
*addr->mailbox == '\0' || *addr->domain == '\0' ?
NULL : t_strconcat(addr->mailbox, "@", addr->domain, NULL);
@@ -799,9 +801,9 @@ int main(int argc, char *argv[])
return EX_TEMPFAIL;
}
- msgid = mail_get_first_header(mail, "Message-ID");
- i_info("msgid=%s: Rejected: %s",
- msgid == NULL ? "" : str_sanitize(msgid, 80),
+ if (mail_get_first_header(mail, "Message-ID", &msgid) <= 0)
+ msgid = "";
+ i_info("msgid=%s: Rejected: %s", str_sanitize(msgid, 80),
str_sanitize(error_string, 512));
/* we'll have to reply with permanent failure */
diff -r f52e7d1402b5 -r eb7c9d8ece54 src/deliver/mail-send.c
--- a/src/deliver/mail-send.c Sun Aug 12 18:16:40 2007 +0300
+++ b/src/deliver/mail-send.c Sun Aug 12 19:40:54 2007 +0300
@@ -31,13 +31,16 @@ get_var_expand_table(struct mail *mail,
{ '\0', NULL }
};
struct var_expand_table *tab;
+ const char *subject;
tab = t_malloc(sizeof(static_tab));
memcpy(tab, static_tab, sizeof(static_tab));
tab[0].value = "\r\n";
tab[1].value = reason;
- tab[2].value = str_sanitize(mail_get_first_header(mail, "Subject"), 80);
+ if (mail_get_first_header(mail, "Subject", &subject) <= 0)
+ subject = "";
+ tab[2].value = str_sanitize(subject, 80);
tab[3].value = recipient;
return tab;
@@ -57,7 +60,8 @@ int mail_send_rejection(struct mail *mai
size_t size;
int ret;
- orig_msgid = mail_get_first_header(mail, "Message-ID");
+ if (mail_get_first_header(mail, "Message-ID", &orig_msgid) < 0)
+ orig_msgid = NULL;
return_addr = deliver_get_return_address(mail);
if (return_addr == NULL) {
i_info("msgid=%s: Return-Path missing, rejection reason: %s",
@@ -102,9 +106,8 @@ int mail_send_rejection(struct mail *mai
boundary);
fprintf(f, "Reporting-UA: %s; Dovecot Mail Delivery Agent\r\n",
deliver_set->hostname);
- str = mail_get_first_header(mail, "Original-Recipient");
- if (str != NULL)
- fprintf(f, "Original-Recipient: rfc822; %s\r\n", str);
+ if (mail_get_first_header(mail, "Original-Recipient", &str) > 0)
+ fprintf(f, "Original-Recipient: rfc822; %s\r\n", str);
fprintf(f, "Final-Recipient: rfc822; %s\r\n", recipient);
if (orig_msgid != NULL)
@@ -116,8 +119,7 @@ int mail_send_rejection(struct mail *mai
/* original message's headers */
fprintf(f, "--%s\r\nContent-Type: message/rfc822\r\n\r\n", boundary);
- input = mail_get_stream(mail, &hdr_size, NULL);
- if (input != NULL) {
+ if (mail_get_stream(mail, &hdr_size, NULL, &input) == 0) {
/* Note: If you add more headers, they need to be sorted.
We'll drop Content-Type because we're not including the message
body, and having a multipart Content-Type may confuse some
@@ -155,16 +157,16 @@ int mail_send_forward(struct mail *mail,
struct smtp_client *smtp_client;
FILE *f;
const unsigned char *data;
+ const char *return_path;
size_t size;
int ret;
- input = mail_get_stream(mail, NULL, NULL);
- if (input == NULL)
+ if (mail_get_stream(mail, NULL, NULL, &input) < 0)
return -1;
- smtp_client = smtp_client_open(forwardto,
- mail_get_first_header(mail, "Return-Path"),
- &f);
+ if (mail_get_first_header(mail, "Return-Path", &return_path) <= 0)
+ return_path = "";
+ smtp_client = smtp_client_open(forwardto, return_path, &f);
input = i_stream_create_header_filter(input, HEADER_FILTER_EXCLUDE |
HEADER_FILTER_NO_CR, hide_headers,
diff -r f52e7d1402b5 -r eb7c9d8ece54 src/imap/imap-fetch-body.c
--- a/src/imap/imap-fetch-body.c Sun Aug 12 18:16:40 2007 +0300
+++ b/src/imap/imap-fetch-body.c Sun Aug 12 19:40:54 2007 +0300
@@ -325,10 +325,9 @@ static int fetch_body(struct imap_fetch_
const struct message_size *fetch_size;
struct message_size hdr_size, body_size;
- ctx->cur_input =
- mail_get_stream(mail, &hdr_size,
- body->section[0] == 'H' ? NULL : &body_size);
- if (ctx->cur_input == NULL)
+ if (mail_get_stream(mail, &hdr_size,
+ body->section[0] == 'H' ? NULL : &body_size,
+ &ctx->cur_input) < 0)
return -1;
i_stream_ref(ctx->cur_input);
@@ -416,8 +415,7 @@ fetch_body_header_partial(struct imap_fe
fetch_body_header_partial(struct imap_fetch_context *ctx, struct mail *mail,
const struct imap_fetch_body_data *body)
{
- ctx->cur_input = mail_get_stream(mail, NULL, NULL);
- if (ctx->cur_input == NULL)
+ if (mail_get_stream(mail, NULL, NULL, &ctx->cur_input) < 0)
return -1;
i_stream_ref(ctx->cur_input);
@@ -439,8 +437,7 @@ fetch_body_header_fields(struct imap_fet
return 0;
}
- ctx->cur_input = mail_get_header_stream(mail, body->header_ctx);
- if (ctx->cur_input == NULL)
+ if (mail_get_header_stream(mail, body->header_ctx, &ctx->cur_input) < 0)
return -1;
i_stream_ref(ctx->cur_input);
@@ -466,8 +463,7 @@ static int part_find(struct mail *mail,
const char *path;
unsigned int num;
- part = mail_get_parts(mail);
- if (part == NULL)
+ if (mail_get_parts(mail, &part) < 0)
return -1;
path = body->section;
@@ -527,8 +523,7 @@ static int fetch_body_mime(struct imap_f
return 1;
}
- ctx->cur_input = mail_get_stream(mail, NULL, NULL);
- if (ctx->cur_input == NULL)
+ if (mail_get_stream(mail, NULL, NULL, &ctx->cur_input) < 0)
return -1;
i_stream_ref(ctx->cur_input);
@@ -861,8 +856,7 @@ static int fetch_rfc822_size(struct imap
{
uoff_t size;
- size = mail_get_virtual_size(mail);
- if (size == (uoff_t)-1)
+ if (mail_get_virtual_size(mail, &size) < 0)
return -1;
str_printfa(ctx->cur_str, "RFC822.SIZE %"PRIuUOFF_T" ", size);
@@ -875,8 +869,7 @@ static int fetch_rfc822(struct imap_fetc
struct message_size hdr_size, body_size;
const char *str;
- ctx->cur_input = mail_get_stream(mail, &hdr_size, &body_size);
- if (ctx->cur_input == NULL)
+ if (mail_get_stream(mail, &hdr_size, &body_size, &ctx->cur_input) < 0)
return -1;
i_stream_ref(ctx->cur_input);
@@ -904,8 +897,7 @@ static int fetch_rfc822_header(struct im
struct message_size hdr_size;
const char *str;
- ctx->cur_input = mail_get_stream(mail, &hdr_size, NULL);
- if (ctx->cur_input == NULL)
+ if (mail_get_stream(mail, &hdr_size, NULL, &ctx->cur_input) < 0)
return -1;
i_stream_ref(ctx->cur_input);
@@ -929,8 +921,7 @@ static int fetch_rfc822_text(struct imap
struct message_size hdr_size, body_size;
const char *str;
- ctx->cur_input = mail_get_stream(mail, &hdr_size, &body_size);
- if (ctx->cur_input == NULL)
+ if (mail_get_stream(mail, &hdr_size, &body_size, &ctx->cur_input) < 0)
return -1;
i_stream_ref(ctx->cur_input);
diff -r f52e7d1402b5 -r eb7c9d8ece54 src/imap/imap-fetch.c
--- a/src/imap/imap-fetch.c Sun Aug 12 18:16:40 2007 +0300
+++ b/src/imap/imap-fetch.c Sun Aug 12 19:40:54 2007 +0300
@@ -403,8 +403,7 @@ static int fetch_body(struct imap_fetch_
{
const char *body;
- body = mail_get_special(mail, MAIL_FETCH_IMAP_BODY);
- if (body == NULL)
+ if (mail_get_special(mail, MAIL_FETCH_IMAP_BODY, &body) < 0)
return -1;
if (ctx->first)
@@ -438,8 +437,8 @@ static int fetch_bodystructure(struct im
{
const char *bodystructure;
- bodystructure = mail_get_special(mail, MAIL_FETCH_IMAP_BODYSTRUCTURE);
- if (bodystructure == NULL)
+ if (mail_get_special(mail, MAIL_FETCH_IMAP_BODYSTRUCTURE,
+ &bodystructure) < 0)
return -1;
if (ctx->first)
@@ -473,8 +472,7 @@ static int fetch_envelope(struct imap_fe
{
const char *envelope;
- envelope = mail_get_special(mail, MAIL_FETCH_IMAP_ENVELOPE);
- if (envelope == NULL)
+ if (mail_get_special(mail, MAIL_FETCH_IMAP_ENVELOPE, &envelope) < 0)
return -1;
if (ctx->first)
@@ -538,14 +536,13 @@ static int fetch_internaldate(struct ima
static int fetch_internaldate(struct imap_fetch_context *ctx, struct mail *mail,
void *context __attr_unused__)
{
- time_t time;
-
- time = mail_get_received_date(mail);
- if (time == (time_t)-1)
+ time_t date;
+
+ if (mail_get_received_date(mail, &date) < 0)
return -1;
str_printfa(ctx->cur_str, "INTERNALDATE \"%s\" ",
- imap_to_datetime(time));
+ imap_to_datetime(date));
return 1;
}
diff -r f52e7d1402b5 -r eb7c9d8ece54 src/imap/imap-thread.c
--- a/src/imap/imap-thread.c Sun Aug 12 18:16:40 2007 +0300
+++ b/src/imap/imap-thread.c Sun Aug 12 19:40:54 2007 +0300
@@ -446,19 +446,24 @@ static void mail_thread_input(struct thr
t_push();
- sent_date = mail_get_date(mail, NULL);
- if (sent_date == (time_t)-1)
+ if (mail_get_date(mail, &sent_date, NULL) < 0)
sent_date = 0;
- message_id = mail_get_first_header(mail, "message-id");
+ if (mail_get_first_header(mail, "message-id", &message_id) < 0)
+ message_id = NULL;
node = update_message(ctx, get_msgid(&message_id), sent_date,
ctx->id_is_uid ? mail->uid : mail->seq);
/* link references */
- references = mail_get_first_header(mail, "references");
+ if (mail_get_first_header(mail, "references", &references) < 0)
+ references = NULL;
+
if (!link_references(ctx, node, references)) {
- in_reply_to = mail_get_first_header(mail, "in-reply-to");
- refid = in_reply_to == NULL ? NULL : get_msgid(&in_reply_to);
+ if (mail_get_first_header(mail, "in-reply-to",
+ &in_reply_to) <= 0)
+ refid = NULL;
More information about the dovecot-cvs
mailing list