summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2019-01-25 22:30:28 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2019-01-25 23:05:52 (GMT)
commit3798a0f09da7fcaa6daa12e9ae483ebf99f7c46a (patch) (side-by-side diff)
tree97c80866168b24c3c45f2d1961311d80b6ff1823
parentbc4d023a3810a7da6ede2cc522cdc34fa3129378 (diff)
downloadmailutils-3798a0f09da7fcaa6daa12e9ae483ebf99f7c46a.tar.gz
mailutils-3798a0f09da7fcaa6daa12e9ae483ebf99f7c46a.tar.bz2
imap4d: implement SEARCH CHARSET; fix BODY and TEXT searches.
* imap4d/search.c: Implement proper BODY searches. Implement CHARSET. * imap4d/util.c (util_strcasestr): Remove. Use mu_c_strcasestr instead. * imap4d/imap4d.h: Likewise. * NEWS: Document changes.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--NEWS11
-rw-r--r--imap4d/imap4d.h1
-rw-r--r--imap4d/search.c458
-rw-r--r--imap4d/util.c8
-rw-r--r--libmailutils/mailbox/header.c4
5 files changed, 341 insertions, 141 deletions
diff --git a/NEWS b/NEWS
index 84d3601..4f5c0de 100644
--- a/NEWS
+++ b/NEWS
@@ -1,2 +1,2 @@
-GNU mailutils NEWS -- history of user-visible changes. 2019-01-23
+GNU mailutils NEWS -- history of user-visible changes. 2019-01-26
Copyright (C) 2002-2019 Free Software Foundation, Inc.
@@ -8,2 +8,11 @@ Version 3.5.90 (git)
+* imap4d: SEARCH command
+
+** Implemented SEARCH CHARSET
+
+** Improved SEARCH BODY and SEARCH TEXT commands
+
+Both commands now properly descend into multipart message parts and
+decode messages, if necessary
+
* Fixes in the 'mail' utility
diff --git a/imap4d/imap4d.h b/imap4d/imap4d.h
index 2ad339a..b90d653 100644
--- a/imap4d/imap4d.h
+++ b/imap4d/imap4d.h
@@ -456,3 +456,2 @@ extern int util_parse_ctime_date (const char *date, time_t *timep,
enum datetime_parse_mode flag);
-extern char *util_strcasestr (const char *haystack, const char *needle);
extern char *util_localname (void);
diff --git a/imap4d/search.c b/imap4d/search.c
index 1d28b57..3c243ed 100644
--- a/imap4d/search.c
+++ b/imap4d/search.c
@@ -17,2 +17,3 @@
#include "imap4d.h"
+#include <mailutils/assoc.h>
@@ -92,3 +93,3 @@ struct search_node
static void cond_msgset (struct parsebuf *, struct search_node *,
- struct value *, struct value *);
+ struct value *, struct value *);
static void cond_bcc (struct parsebuf *, struct search_node *,
@@ -96,21 +97,21 @@ static void cond_bcc (struct parsebuf *, struct search_node *,
static void cond_before (struct parsebuf *, struct search_node *,
- struct value *, struct value *);
+ struct value *, struct value *);
static void cond_body (struct parsebuf *, struct search_node *,
- struct value *, struct value *);
+ struct value *, struct value *);
static void cond_cc (struct parsebuf *, struct search_node *,
- struct value *, struct value *);
+ struct value *, struct value *);
static void cond_from (struct parsebuf *, struct search_node *,
- struct value *, struct value *);
+ struct value *, struct value *);
static void cond_header (struct parsebuf *, struct search_node *,
- struct value *, struct value *);
+ struct value *, struct value *);
static void cond_keyword (struct parsebuf *, struct search_node *,
- struct value *, struct value *);
+ struct value *, struct value *);
static void cond_larger (struct parsebuf *, struct search_node *,
- struct value *, struct value *);
+ struct value *, struct value *);
static void cond_on (struct parsebuf *, struct search_node *,
- struct value *, struct value *);
+ struct value *, struct value *);
static void cond_sentbefore (struct parsebuf *, struct search_node *,
- struct value *, struct value *);
+ struct value *, struct value *);
static void cond_senton (struct parsebuf *, struct search_node *,
- struct value *, struct value *);
+ struct value *, struct value *);
static void cond_sentsince (struct parsebuf *, struct search_node *,
@@ -118,13 +119,13 @@ static void cond_sentsince (struct parsebuf *, struct search_node *,
static void cond_since (struct parsebuf *, struct search_node *,
- struct value *, struct value *);
+ struct value *, struct value *);
static void cond_smaller (struct parsebuf *, struct search_node *,
- struct value *, struct value *);
+ struct value *, struct value *);
static void cond_subject (struct parsebuf *, struct search_node *,
- struct value *, struct value *);
+ struct value *, struct value *);
static void cond_text (struct parsebuf *, struct search_node *,
- struct value *, struct value *);
+ struct value *, struct value *);
static void cond_to (struct parsebuf *, struct search_node *,
- struct value *, struct value *);
+ struct value *, struct value *);
static void cond_uid (struct parsebuf *, struct search_node *,
- struct value *, struct value *);
+ struct value *, struct value *);
@@ -140,3 +141,3 @@ struct cond
/* Types are: s -- string
- n -- number
+ n -- number
d -- date
@@ -215,3 +216,3 @@ struct mem_chain
that they are enclosed in doublequotes */
-#define MAXTOKEN 64
+#define MAXTOKEN 64
@@ -220,14 +221,15 @@ struct parsebuf
{
- imap4d_tokbuf_t tok; /* Token buffer */
+ imap4d_tokbuf_t tok; /* Token buffer */
int arg; /* Argument number */
char *token; /* Current token */
- int isuid; /* UIDs instead of msgnos are required */
+ int isuid; /* UIDs instead of msgnos are required */
char *err_mesg; /* Error message if a parse error occured */
struct mem_chain *alloc; /* Chain of objects allocated during parsing */
-
+ char *charset; /* Charset, other than US-ASCII requested */
+
struct search_node *tree; /* Parse tree */
-
- /* Execution time only: */
+
+ /* Execution time only: */
size_t msgno; /* Number of current message */
- mu_message_t msg; /* Current message */
+ mu_message_t msg; /* Current message */
};
@@ -243,2 +245,3 @@ static int search_run (struct parsebuf *pb);
static void do_search (struct parsebuf *pb);
+static int available_charset (const char *charset);
@@ -248,3 +251,3 @@ static void do_search (struct parsebuf *pb);
Arguments: OPTIONAL [CHARSET] specification
- searching criteria (one or more)
+ searching criteria (one or more)
@@ -253,5 +256,5 @@ static void do_search (struct parsebuf *pb);
Result: OK - search completed
- NO - search error: can't search that [CHARSET] or
- criteria
- BAD - command unknown or arguments invalid
+ NO - search error: can't search that [CHARSET] or
+ criteria
+ BAD - command unknown or arguments invalid
*/
@@ -260,3 +263,3 @@ int
imap4d_search (struct imap4d_session *session,
- struct imap4d_command *command, imap4d_tokbuf_t tok)
+ struct imap4d_command *command, imap4d_tokbuf_t tok)
{
@@ -264,3 +267,3 @@ imap4d_search (struct imap4d_session *session,
char *err_text= "";
-
+
rc = imap4d_search0 (tok, 0, &err_text);
@@ -268,3 +271,3 @@ imap4d_search (struct imap4d_session *session,
}
-
+
int
@@ -273,3 +276,3 @@ imap4d_search0 (imap4d_tokbuf_t tok, int isuid, char **err_text)
struct parsebuf parsebuf;
-
+
memset (&parsebuf, 0, sizeof(parsebuf));
@@ -286,3 +289,3 @@ imap4d_search0 (imap4d_tokbuf_t tok, int isuid, char **err_text)
}
-
+
if (mu_c_strcasecmp (parsebuf.token, "CHARSET") == 0)
@@ -298,5 +301,11 @@ imap4d_search0 (imap4d_tokbuf_t tok, int isuid, char **err_text)
{
- *err_text = "Charset not supported";
- return RESP_NO;
+ parsebuf.charset = parse_strdup (&parsebuf, parsebuf.token);
+ if (!available_charset (parsebuf.charset))
+ {
+ *err_text = "[BADCHARSET] Charset not supported";
+ return RESP_NO;
+ }
}
+ else
+ parsebuf.charset = NULL;
@@ -307,3 +316,2 @@ imap4d_search0 (imap4d_tokbuf_t tok, int isuid, char **err_text)
}
-
}
@@ -325,8 +333,8 @@ imap4d_search0 (imap4d_tokbuf_t tok, int isuid, char **err_text)
}
-
+
/* Execute compiled expression */
do_search (&parsebuf);
-
+
parse_free_mem (&parsebuf);
-
+
*err_text = "Completed";
@@ -341,3 +349,3 @@ do_search (struct parsebuf *pb)
size_t count = 0;
-
+
mu_mailbox_messages_count (mbox, &count);
@@ -419,3 +427,3 @@ parse_alloc (struct parsebuf *pb, size_t size)
-/* Create a copy of the string. */
+/* Create a copy of the string. */
char *
@@ -447,3 +455,3 @@ parse_msgset_create (struct parsebuf *pb, mu_mailbox_t mbox, int flags)
search_key_list : search_key
- | search_key_list search_key
+ | search_key_list search_key
;
@@ -451,3 +459,3 @@ parse_msgset_create (struct parsebuf *pb, mu_mailbox_t mbox, int flags)
search_key : simple_key
- | NOT simple_key
+ | NOT simple_key
| OR simple_key simple_key
@@ -488,3 +496,3 @@ parse_search_key (struct parsebuf *pb)
struct search_node *node;
-
+
if (strcmp (pb->token, "(") == 0)
@@ -493,3 +501,3 @@ parse_search_key (struct parsebuf *pb)
return NULL;
-
+
node = parse_search_key_list (pb);
@@ -497,3 +505,3 @@ parse_search_key (struct parsebuf *pb)
return NULL;
-
+
if (strcmp (pb->token, ")"))
@@ -583,3 +591,3 @@ parse_equiv_key (struct parsebuf *pb)
__FILE__, __LINE__);
- abort ();
+ abort ();
}
@@ -603,3 +611,3 @@ parse_simple_key (struct parsebuf *pb)
;
-
+
if (!condp->name)
@@ -607,6 +615,6 @@ parse_simple_key (struct parsebuf *pb)
mu_msgset_t msgset = parse_msgset_create (pb, mbox, MU_MSGSET_NUM);
-
+
if (mu_msgset_parse_imap (msgset,
pb->isuid ? MU_MSGSET_UID : MU_MSGSET_NUM,
- pb->token, NULL) == 0)
+ pb->token, NULL) == 0)
{
@@ -616,3 +624,3 @@ parse_simple_key (struct parsebuf *pb)
np->v.value.v.msgset = msgset;
-
+
node = parse_alloc (pb, sizeof *node);
@@ -623,5 +631,5 @@ parse_simple_key (struct parsebuf *pb)
node->v.key.fun = cond_msgset;
-
+
parse_gettoken (pb, 0);
-
+
return node;
@@ -634,3 +642,3 @@ parse_simple_key (struct parsebuf *pb)
}
-
+
node = parse_alloc (pb, sizeof *node);
@@ -640,3 +648,3 @@ parse_simple_key (struct parsebuf *pb)
node->v.key.narg = 0;
-
+
parse_gettoken (pb, 0);
@@ -648,3 +656,3 @@ parse_simple_key (struct parsebuf *pb)
struct search_node *arg;
-
+
for (; *t; t++, parse_gettoken (pb, 0))
@@ -656,3 +664,3 @@ parse_simple_key (struct parsebuf *pb)
}
-
+
if (!pb->token)
@@ -662,3 +670,3 @@ parse_simple_key (struct parsebuf *pb)
}
-
+
arg = parse_alloc (pb, sizeof *arg);
@@ -671,3 +679,3 @@ parse_simple_key (struct parsebuf *pb)
break;
-
+
case 'n': /* number */
@@ -682,3 +690,3 @@ parse_simple_key (struct parsebuf *pb)
break;
-
+
case 'd': /* date */
@@ -693,3 +701,3 @@ parse_simple_key (struct parsebuf *pb)
break;
-
+
case 'u': /* UID message set */
@@ -699,3 +707,3 @@ parse_simple_key (struct parsebuf *pb)
if (mu_msgset_parse_imap (arg->v.value.v.msgset, MU_MSGSET_UID,
- pb->token, NULL))
+ pb->token, NULL))
{
@@ -705,3 +713,3 @@ parse_simple_key (struct parsebuf *pb)
break;
-
+
default:
@@ -713,3 +721,3 @@ parse_simple_key (struct parsebuf *pb)
node->v.key.arg[node->v.key.narg++] = arg;
- }
+ }
}
@@ -725,3 +733,3 @@ evaluate_node (struct search_node *node, struct parsebuf *pb,
struct value argval[MAX_NODE_ARGS];
-
+
switch (node->type)
@@ -735,3 +743,3 @@ evaluate_node (struct search_node *node, struct parsebuf *pb,
}
-
+
node->v.key.fun (pb, node, argval, val);
@@ -750,3 +758,3 @@ evaluate_node (struct search_node *node, struct parsebuf *pb,
break;
-
+
case node_or:
@@ -768,3 +776,3 @@ evaluate_node (struct search_node *node, struct parsebuf *pb,
break;
-
+
case node_value:
@@ -798,11 +806,34 @@ _scan_header (struct parsebuf *pb, char *name, char *value)
{
- const char *hval;
+ char *hval;
mu_header_t header = NULL;
-
+ int i, rc;
+ int result = 0;
+
mu_message_get_header (pb->msg, &header);
- if (mu_header_sget_value (header, name, &hval) == 0)
+
+ for (i = 1;
+ result == 0
+ && (rc = mu_header_aget_value_unfold_n (header, name, i, &hval)) == 0;
+ i++)
{
- return util_strcasestr (hval, value) != NULL;
+ if (pb->charset)
+ {
+ char *tmp;
+ rc = mu_rfc2047_decode (pb->charset, hval, &tmp);
+ if (rc)
+ {
+ mu_diag_funcall (MU_DIAG_ERR, "mu_rfc2047_decode", hval, rc);
+ free (hval);
+ continue;
+ }
+ free (hval);
+ hval = tmp;
+ }
+ result = mu_c_strcasestr (hval, value) != NULL;
+ free (hval);
}
- return 0;
+ if (!(rc == 0 || rc == MU_ERR_NOENT))
+ mu_diag_funcall (MU_DIAG_ERR, "mu_header_aget_value_unfold_n", NULL, rc);
+
+ return result;
}
@@ -815,3 +846,3 @@ _header_date (struct parsebuf *pb, time_t *timep)
mu_header_t header = NULL;
-
+
mu_message_get_header (pb->msg, &header);
@@ -827,3 +858,2 @@ _scan_header_all (struct parsebuf *pb, char *text)
{
- const char *hval;
mu_header_t header = NULL;
@@ -831,2 +861,3 @@ _scan_header_all (struct parsebuf *pb, char *text)
int i, rc;
+ int result;
@@ -834,38 +865,183 @@ _scan_header_all (struct parsebuf *pb, char *text)
mu_header_get_field_count (header, &fcount);
- for (i = rc = 0; i < fcount; i++)
+ result = 0;
+ for (i = 1; result == 0 && i < fcount; i++)
{
- if (mu_header_sget_field_value (header, i, &hval) == 0)
- rc = util_strcasestr (hval, text) != NULL;
+ char *hval;
+
+ rc = mu_header_aget_field_value_unfold (header, i, &hval);
+ if (rc)
+ {
+ mu_diag_funcall (MU_DIAG_ERR, "mu_header_aget_field_value_unfold",
+ NULL, rc);
+ continue;
+ }
+
+ if (pb->charset)
+ {
+ char *tmp;
+ rc = mu_rfc2047_decode (pb->charset, hval, &tmp);
+ if (rc)
+ {
+ mu_diag_funcall (MU_DIAG_ERR, "mu_rfc2047_decode", hval, rc);
+ free (hval);
+ continue;
+ }
+
+ free (hval);
+ hval = tmp;
+ }
+ result = mu_c_strcasestr (hval, text) != NULL;
+ free (hval);
}
- return rc;
+ return result;
}
-
-/* Scan body of the message for the occurrence of a substring */
-/* FIXME: The algorithm below is broken */
+
static int
-_scan_body (struct parsebuf *pb, char *text)
+_match_text (struct parsebuf *pb, mu_message_t msg, mu_content_type_t ct,
+ char const *encoding,
+ char *text)
{
- mu_body_t body = NULL;
- mu_stream_t stream = NULL;
- size_t size = 0, lines = 0;
- char buffer[128];
- size_t n = 0;
+ mu_body_t body;
+ mu_stream_t str;
int rc;
-
- mu_message_get_body (pb->msg, &body);
- mu_body_size (body, &size);
- mu_body_lines (body, &lines);
- mu_body_get_streamref (body, &stream);
- rc = 0;
- while (rc == 0
- && mu_stream_read (stream, buffer, sizeof(buffer)-1, &n) == 0
+ int result;
+ char *buffer = NULL;
+ size_t bufsize = 0;
+ size_t n;
+
+ mu_message_get_body (msg, &body);
+ mu_body_get_streamref (body, &str);
+
+ if (encoding)
+ {
+ mu_stream_t flt;
+ rc = mu_filter_create (&flt, str, encoding,
+ MU_FILTER_DECODE,
+ MU_STREAM_READ);
+ mu_stream_unref (str);
+ if (rc)
+ {
+ mu_error (_("can't handle encoding %s: %s"),
+ encoding, mu_strerror (rc));
+ return 0;
+ }
+ str = flt;
+ }
+
+ if (pb->charset)
+ {
+ struct mu_mime_param *param;
+ if (mu_assoc_lookup (ct->param, "charset", &param) == 0
+ && mu_c_strcasecmp (param->value, pb->charset))
+ {
+ char const *argv[] = { "iconv", NULL, NULL, NULL };
+ mu_stream_t flt;
+
+ argv[1] = param->value;
+ argv[2] = pb->charset;
+ rc = mu_filter_chain_create (&flt, str,
+ MU_FILTER_ENCODE,
+ MU_STREAM_READ,
+ MU_ARRAY_SIZE (argv) - 1,
+ (char**) argv);
+ mu_stream_unref (str);
+ if (rc)
+ {
+ mu_error (_("can't convert from charset %s to %s"),
+ param->value, pb->charset);
+ return 0;
+ }
+ str = flt;
+ }
+ }
+
+ result = 0;
+ while ((rc = mu_stream_getline (str, &buffer, &bufsize, &n)) == 0
&& n > 0)
{
- buffer[n] = 0;
- rc = util_strcasestr (buffer, text) != NULL;
+ result = mu_c_strcasestr (buffer, text) != NULL;
+ if (result)
+ break;
}
- mu_stream_destroy (&stream);
- return rc;
+ mu_stream_destroy (&str);
+ if (rc)
+ mu_diag_funcall (MU_DIAG_ERR, "mu_stream_getline", NULL, rc);
+ return result;
}
+static int
+_match_multipart (struct parsebuf *pb, mu_message_t msg, char *text)
+{
+ mu_header_t hdr;
+ char *encoding;
+ int ismp;
+ int result;
+ mu_content_type_t ct;
+ char *buf;
+ int rc;
+
+ if (mu_message_is_multipart (msg, &ismp))
+ return 0;
+ if (mu_message_get_header (msg, &hdr))
+ return 0;
+
+ if (mu_header_aget_value_unfold (hdr, MU_HEADER_CONTENT_TYPE, &buf))
+ {
+ buf = strdup ("text/plain");
+ if (!buf)
+ return 0;
+ }
+ rc = mu_content_type_parse (buf, NULL, &ct);
+ free (buf);
+ if (rc)
+ return 0;
+
+ if (mu_header_aget_value_unfold (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING,
+ &encoding))
+ encoding = NULL;
+
+ if (ismp)
+ {
+ size_t i, nparts;
+
+ mu_message_get_num_parts (msg, &nparts);
+
+ for (i = 1; i <= nparts; i++)
+ {
+ mu_message_t submsg = NULL;
+
+ if (mu_message_get_part (msg, i, &submsg) == 0)
+ {
+ result = _match_multipart (pb, submsg, text);
+ if (result)
+ break;
+ }
+ }
+ }
+ else if (mu_c_strcasecmp (ct->type, "message") == 0
+ && mu_c_strcasecmp (ct->subtype, "rfc822") == 0)
+ {
+ mu_message_t submsg = NULL;
+
+ if (mu_message_unencapsulate (msg, &submsg, NULL) == 0)
+ {
+ result = _match_multipart (pb, submsg, text);
+ }
+ }
+ else if (mu_c_strcasecmp (ct->type, "text") == 0)
+ result = _match_text (pb, msg, ct, encoding, text);
+
+ free (encoding);
+ mu_content_type_destroy (&ct);
+
+ return result;
+}
+
+/* Scan body of the message for the occurrence of a substring */
+static int
+_scan_body (struct parsebuf *pb, char *text)
+{
+ return _match_multipart (pb, pb->msg, text);
+}
+
/* Basic instructions */
@@ -887,3 +1063,3 @@ cond_bcc (struct parsebuf *pb, struct search_node *node, struct value *arg,
retval->v.number = _scan_header (pb, MU_HEADER_BCC, arg[0].v.string);
-}
+}
@@ -897,3 +1073,3 @@ cond_before (struct parsebuf *pb, struct search_node *node, struct value *arg,
mu_envelope_t env;
-
+
mu_message_get_envelope (pb->msg, &env);
@@ -907,3 +1083,3 @@ cond_before (struct parsebuf *pb, struct search_node *node, struct value *arg,
}
-}
+}
@@ -915,3 +1091,3 @@ cond_body (struct parsebuf *pb, struct search_node *node, struct value *arg,
retval->v.number = _scan_body (pb, arg[0].v.string);
-}
+}
@@ -923,3 +1099,3 @@ cond_cc (struct parsebuf *pb, struct search_node *node, struct value *arg,
retval->v.number = _scan_header (pb, MU_HEADER_CC, arg[0].v.string);
-}
+}
@@ -933,10 +1109,10 @@ cond_from (struct parsebuf *pb, struct search_node *node, struct value *arg,
int rc = 0;
-
+
mu_message_get_envelope (pb->msg, &env);
if (mu_envelope_sget_sender (env, &from) == 0)
- rc = util_strcasestr (from, s) != NULL;
-
+ rc = mu_c_strcasestr (from, s) != NULL;
+
retval->type = value_number;
retval->v.number = rc || _scan_header (pb, MU_HEADER_FROM, s);
-}
+}
@@ -951,3 +1127,3 @@ cond_header (struct parsebuf *pb, struct search_node *node, struct value *arg,
retval->v.number = _scan_header (pb, name, value);
-}
+}
@@ -959,3 +1135,3 @@ cond_keyword (struct parsebuf *pb, struct search_node *node, struct value *arg,
mu_attribute_t attr = NULL;
-
+
mu_message_get_attribute (pb->msg, &attr);
@@ -963,3 +1139,3 @@ cond_keyword (struct parsebuf *pb, struct search_node *node, struct value *arg,
retval->v.number = util_attribute_matches_flag (attr, s);
-}
+}
@@ -970,3 +1146,3 @@ cond_larger (struct parsebuf *pb, struct search_node *node, struct value *arg,
size_t size = 0;
-
+
mu_message_size (pb->msg, &size);
@@ -974,3 +1150,3 @@ cond_larger (struct parsebuf *pb, struct search_node *node, struct value *arg,
retval->v.number = size > arg[0].v.number;
-}
+}
@@ -984,3 +1160,3 @@ cond_on (struct parsebuf *pb, struct search_node *node, struct value *arg,
mu_envelope_t env;
-
+
mu_message_get_envelope (pb->msg, &env);
@@ -994,3 +1170,3 @@ cond_on (struct parsebuf *pb, struct search_node *node, struct value *arg,
}
-}
+}
@@ -1007,3 +1183,3 @@ cond_sentbefore (struct parsebuf *pb, struct search_node *node,
retval->v.number = mesg_time < t;
-}
+}
@@ -1019,3 +1195,3 @@ cond_senton (struct parsebuf *pb, struct search_node *node, struct value *arg,
retval->v.number = t <= mesg_time && mesg_time <= t + 86400;
-}
+}
@@ -1032,3 +1208,3 @@ cond_sentsince (struct parsebuf *pb, struct search_node *node,
retval->v.number = mesg_time >= t;
-}
+}
@@ -1042,3 +1218,3 @@ cond_since (struct parsebuf *pb, struct search_node *node, struct value *arg,
mu_envelope_t env;
-
+
mu_message_get_envelope (pb->msg, &env);
@@ -1052,3 +1228,3 @@ cond_since (struct parsebuf *pb, struct search_node *node, struct value *arg,
}
-}
+}
@@ -1059,3 +1235,3 @@ cond_smaller (struct parsebuf *pb, struct search_node *node, struct value *arg,
size_t size = 0;
-
+
mu_message_size (pb->msg, &size);
@@ -1063,3 +1239,3 @@ cond_smaller (struct parsebuf *pb, struct search_node *node, struct value *arg,
retval->v.number = size < arg[0].v.number;
-}
+}
@@ -1071,3 +1247,3 @@ cond_subject (struct parsebuf *pb, struct search_node *node, struct value *arg,
retval->v.number = _scan_header (pb, MU_HEADER_SUBJECT, arg[0].v.string);
-}
+}
@@ -1080,3 +1256,3 @@ cond_text (struct parsebuf *pb, struct search_node *node, struct value *arg,
retval->v.number = _scan_header_all (pb, s) || _scan_body (pb, s);
-}
+}
@@ -1088,3 +1264,3 @@ cond_to (struct parsebuf *pb, struct search_node *node, struct value *arg,
retval->v.number = _scan_header (pb, MU_HEADER_TO, arg[0].v.string);
-}
+}
@@ -1096,3 +1272,3 @@ cond_uid (struct parsebuf *pb, struct search_node *node, struct value *arg,
size_t uid = 0;
-
+
mu_message_get_uid (pb->msg, &uid);
@@ -1101,3 +1277,27 @@ cond_uid (struct parsebuf *pb, struct search_node *node, struct value *arg,
retval->v.number = rc == 0;
-}
+}
+/* Return 1 if the CHARSET is available.
+ This function assumes that charset is available if it is possible
+ to create a filter for encoding ASCII data into it.
+ */
+static int
+available_charset (const char *charset)
+{
+ int rc;
+ mu_stream_t flt;
+ mu_stream_t null;
+ char const *argv[] = { "iconv", "US-ASCII", NULL, NULL };
+
+ rc = mu_nullstream_create (&null, MU_STREAM_READ);
+ if (rc)
+ return 0;
+ argv[2] = charset;
+ rc = mu_filter_chain_create (&flt, null, MU_FILTER_ENCODE, MU_STREAM_READ,
+ MU_ARRAY_SIZE (argv) - 1, (char**) argv);
+ mu_stream_unref (null);
+ if (rc)
+ return 0;
+ mu_stream_destroy (&flt);
+ return 1;
+}
diff --git a/imap4d/util.c b/imap4d/util.c
index 19a7d82..cc49478 100644
--- a/imap4d/util.c
+++ b/imap4d/util.c
@@ -158,10 +158,2 @@ util_parse_ctime_date (const char *date, time_t *timep,
-/* Return the first ocurrence of NEEDLE in HAYSTACK. Case insensitive
- comparison */
-char *
-util_strcasestr (const char *haystack, const char *needle)
-{
- return mu_c_strcasestr (haystack, needle);
-}
-
void
diff --git a/libmailutils/mailbox/header.c b/libmailutils/mailbox/header.c
index 66af142..98433b7 100644
--- a/libmailutils/mailbox/header.c
+++ b/libmailutils/mailbox/header.c
@@ -690,4 +690,4 @@ int
mu_header_aget_value_n (mu_header_t header,
- const char *name, int n,
- char **pval)
+ const char *name, int n,
+ char **pval)
{

Return to:

Send suggestions and report system problems to the System administrator.