summaryrefslogtreecommitdiff
path: root/libmailutils
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-12-30 21:26:36 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2010-12-30 21:45:59 +0200
commite9b90de7b7807f0828243e04785b03d9de0055e3 (patch)
treea9d10ad36f3d363911050755359e71b06232879c /libmailutils
parentb6a162923d3fdfc0c8642dd0169bf870a5ae2868 (diff)
downloadmailutils-e9b90de7b7807f0828243e04785b03d9de0055e3.tar.gz
mailutils-e9b90de7b7807f0828243e04785b03d9de0055e3.tar.bz2
Provide a function for quick retrieval of message lines.
* include/mailutils/message.h (mu_message_quick_lines): New proto. (mu_message_set_lines): Change signature of the 2nd argument. * include/mailutils/sys/message.h (_mu_message) <lines>: Change signature. * libmailutils/diag/errors (MU_ERR_INFO_UNAVAILABLE): New error code. * libmailutils/mailbox/message.c (mu_message_set_lines): Change signature of the 2nd argument. (mu_message_lines): Update call to the _lines method. (mu_message_quick_lines): New function. * libproto/pop/mbox.c (_POP3_MSG_LINES): New flag. (_pop3_message)<message_lines>: New member. (pop_create_pop3_message): New function. (pop_scan): Use LIST to obtain scan listing. (pop_message_lines): New function. (pop_create_message): Set _lines method. (pop_get_message): Use pop_create_pop3_message. * mail/from.c (hdr_quick_lines): New function. (compile_headline): New escape %L * pop3d/capa.c (pop3d_capa): Show XLINES capability if configured. * pop3d/list.c (pop3d_list): Optionally output the number of lines in the message. * pop3d/pop3d.c (pop3d_xlines): New global. (pop3d_cfg_param): New statement "scan-lines". * pop3d/pop3d.h (pop3d_xlines): New extern.
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.