dovecot-2.2: imap_msgpart_parse() doesn't really need a mailbox ...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Aug 13 02:41:14 EEST 2012
details: http://hg.dovecot.org/dovecot-2.2/rev/cf79ab812651
changeset: 14888:cf79ab812651
user: Timo Sirainen <tss at iki.fi>
date: Mon Aug 13 02:41:08 2012 +0300
description:
imap_msgpart_parse() doesn't really need a mailbox parameter.
diffstat:
src/imap/imap-fetch-body.c | 6 ++----
src/lib-imap-storage/imap-msgpart-url.c | 2 +-
src/lib-imap-storage/imap-msgpart.c | 28 +++++++++++++++++-----------
src/lib-imap-storage/imap-msgpart.h | 8 ++++++--
4 files changed, 26 insertions(+), 18 deletions(-)
diffs (141 lines):
diff -r 0c73a42c194e -r cf79ab812651 src/imap/imap-fetch-body.c
--- a/src/imap/imap-fetch-body.c Mon Aug 13 01:47:54 2012 +0300
+++ b/src/imap/imap-fetch-body.c Mon Aug 13 02:41:08 2012 +0300
@@ -312,8 +312,7 @@
body->section, p);
p++;
}
- if (imap_msgpart_parse(ctx->fetch_ctx->box, body->section,
- &body->msgpart) < 0) {
+ if (imap_msgpart_parse(body->section, &body->msgpart) < 0) {
ctx->error = "Invalid BODY[..] section";
return -1;
}
@@ -383,8 +382,7 @@
body->section, p);
p++;
}
- if (imap_msgpart_parse(ctx->fetch_ctx->box, body->section,
- &body->msgpart) < 0) {
+ if (imap_msgpart_parse(body->section, &body->msgpart) < 0) {
ctx->error = "Invalid BINARY[..] section";
return -1;
}
diff -r 0c73a42c194e -r cf79ab812651 src/lib-imap-storage/imap-msgpart-url.c
--- a/src/lib-imap-storage/imap-msgpart-url.c Mon Aug 13 01:47:54 2012 +0300
+++ b/src/lib-imap-storage/imap-msgpart-url.c Mon Aug 13 02:41:08 2012 +0300
@@ -174,7 +174,7 @@
if ((ret = imap_msgpart_url_open_mail(mpurl, mail_r, error_r)) <= 0)
return ret;
- if (imap_msgpart_parse((*mail_r)->box, section, msgpart_r) < 0) {
+ if (imap_msgpart_parse(section, msgpart_r) < 0) {
*error_r = "Invalid section";
return 0;
}
diff -r 0c73a42c194e -r cf79ab812651 src/lib-imap-storage/imap-msgpart.c
--- a/src/lib-imap-storage/imap-msgpart.c Mon Aug 13 01:47:54 2012 +0300
+++ b/src/lib-imap-storage/imap-msgpart.c Mon Aug 13 02:41:08 2012 +0300
@@ -172,8 +172,7 @@
}
static int
-imap_msgpart_parse_header_fields(struct mailbox *box,
- struct imap_msgpart *msgpart,
+imap_msgpart_parse_header_fields(struct imap_msgpart *msgpart,
const char *header_list)
{
ARRAY_TYPE(const_string) fields;
@@ -185,12 +184,10 @@
array_append_zero(&fields);
msgpart->headers = array_idx(&fields, 0);
- msgpart->header_ctx = mailbox_header_lookup_init(box, msgpart->headers);
return 0;
}
-int imap_msgpart_parse(struct mailbox *box, const char *section,
- struct imap_msgpart **msgpart_r)
+int imap_msgpart_parse(const char *section, struct imap_msgpart **msgpart_r)
{
struct imap_msgpart *msgpart;
pool_t pool;
@@ -263,11 +260,11 @@
ret = 0;
} else if (strncmp(section, "HEADER.FIELDS ", 14) == 0) {
msgpart->fetch_type = FETCH_HEADER_FIELDS;
- ret = imap_msgpart_parse_header_fields(box, msgpart,
+ ret = imap_msgpart_parse_header_fields(msgpart,
section+14);
} else if (strncmp(section, "HEADER.FIELDS.NOT ", 18) == 0) {
msgpart->fetch_type = FETCH_HEADER_FIELDS_NOT;
- ret = imap_msgpart_parse_header_fields(box, msgpart,
+ ret = imap_msgpart_parse_header_fields(msgpart,
section+18);
} else {
ret = -1;
@@ -295,8 +292,7 @@
*_msgpart = NULL;
- if (msgpart->header_ctx != NULL)
- mailbox_header_lookup_unref(&msgpart->header_ctx);
+ imap_msgpart_close_mailbox(msgpart);
pool_unref(&msgpart->pool);
}
@@ -547,7 +543,7 @@
}
static int
-imap_msgpart_open_normal(struct mail *mail, const struct imap_msgpart *msgpart,
+imap_msgpart_open_normal(struct mail *mail, struct imap_msgpart *msgpart,
const struct message_part *part,
struct message_size *part_size_r,
struct imap_msgpart_open_result *result_r)
@@ -588,7 +584,11 @@
break;
case FETCH_HEADER_FIELDS:
/* try to lookup the headers from cache */
- i_assert(msgpart->header_ctx != NULL);
+ if (msgpart->header_ctx == NULL) {
+ msgpart->header_ctx =
+ mailbox_header_lookup_init(mail->box,
+ msgpart->headers);
+ }
if (mail_get_header_stream(mail, msgpart->header_ctx,
&input) < 0)
return -1;
@@ -720,3 +720,9 @@
include_hdr = msgpart->fetch_type == FETCH_FULL;
return mail_get_binary_size(mail, part, include_hdr, size_r);
}
+
+void imap_msgpart_close_mailbox(struct imap_msgpart *msgpart)
+{
+ if (msgpart->header_ctx != NULL)
+ mailbox_header_lookup_unref(&msgpart->header_ctx);
+}
diff -r 0c73a42c194e -r cf79ab812651 src/lib-imap-storage/imap-msgpart.h
--- a/src/lib-imap-storage/imap-msgpart.h Mon Aug 13 01:47:54 2012 +0300
+++ b/src/lib-imap-storage/imap-msgpart.h Mon Aug 13 02:41:08 2012 +0300
@@ -21,8 +21,7 @@
/* Parse section into imap_msgpart. Returns 0 and msgpart_r on success,
-1 if the section isn't valid. The same imap_msgpart can be used to open
multiple messages. */
-int imap_msgpart_parse(struct mailbox *box, const char *section,
- struct imap_msgpart **msgpart_r);
+int imap_msgpart_parse(const char *section, struct imap_msgpart **msgpart_r);
void imap_msgpart_free(struct imap_msgpart **msgpart);
/* Decode MIME parts with Content-Transfer-Encoding: base64/quoted-printable
@@ -46,4 +45,9 @@
int imap_msgpart_size(struct mail *mail, struct imap_msgpart *msgpart,
size_t *size_r);
+/* Header context is automatically created by imap_msgpart_open() and destroyed
+ by imap_msgpart_free(), but if you want to use the same imap_msgpart across
+ multiple mailboxes, you need to close the part before closing the mailbox. */
+void imap_msgpart_close_mailbox(struct imap_msgpart *msgpart);
+
#endif
More information about the dovecot-cvs
mailing list