summaryrefslogtreecommitdiff
path: root/libmailutils
diff options
context:
space:
mode:
Diffstat (limited to 'libmailutils')
-rw-r--r--libmailutils/diag/errors2
-rw-r--r--libmailutils/mailbox/message.c34
2 files changed, 34 insertions, 2 deletions
diff --git a/libmailutils/diag/errors b/libmailutils/diag/errors
index 3807524b6..0b71e3ccd 100644
--- a/libmailutils/diag/errors
+++ b/libmailutils/diag/errors
@@ -95,3 +95,5 @@ MU_ERR_AUTH_NO_CRED _("No credentials supplied")
MU_ERR_URL_MISS_PARTS _("URL missing required parts")
MU_ERR_URL_EXTRA_PARTS _("URL has parts not allowed by its scheme")
+
+MU_ERR_INFO_UNAVAILABLE _("Information is not yet available")
diff --git a/libmailutils/mailbox/message.c b/libmailutils/mailbox/message.c
index 684fe39e4..2a2ebe3dd 100644
--- a/libmailutils/mailbox/message.c
+++ b/libmailutils/mailbox/message.c
@@ -882,7 +882,7 @@ mu_message_set_get_stream (mu_message_t msg,
int
mu_message_set_lines (mu_message_t msg, int (*_lines)
- (mu_message_t, size_t *), void *owner)
+ (mu_message_t, size_t *, int), void *owner)
{
if (msg == NULL)
return EINVAL;
@@ -902,7 +902,7 @@ mu_message_lines (mu_message_t msg, size_t *plines)
return EINVAL;
/* Overload. */
if (msg->_lines)
- return msg->_lines (msg, plines);
+ return msg->_lines (msg, plines, 0);
if (plines)
{
hlines = blines = 0;
@@ -913,6 +913,36 @@ mu_message_lines (mu_message_t msg, size_t *plines)
return ret;
}
+/* Return the number of lines in the message, without going into
+ excess trouble for calculating it. If obtaining the result
+ means downloading the entire message (as is the case for POP3,
+ for example), return MU_ERR_INFO_UNAVAILABLE. */
+int
+mu_message_quick_lines (mu_message_t msg, size_t *plines)
+{
+ size_t hlines, blines;
+ int rc;
+
+ if (msg == NULL)
+ return EINVAL;
+ /* Overload. */
+ if (msg->_lines)
+ {
+ int rc = msg->_lines (msg, plines, 1);
+ if (rc != ENOSYS)
+ return rc;
+ }
+ if (plines)
+ {
+ hlines = blines = 0;
+ if ((rc = mu_header_lines (msg->header, &hlines)) == 0)
+ rc = mu_body_lines (msg->body, &blines);
+ if (rc == 0)
+ *plines = hlines + blines;
+ }
+ return rc;
+}
+
int
mu_message_set_size (mu_message_t msg, int (*_size)
(mu_message_t, size_t *), void *owner)

Return to:

Send suggestions and report system problems to the System administrator.