[dovecot-cvs] dovecot/src/lib-imap imap-envelope.c,1.18,1.19 imap-envelope.h,1.5,1.6

cras at procontrol.fi cras at procontrol.fi
Thu Jan 2 11:06:35 EET 2003


Update of /home/cvs/dovecot/src/lib-imap
In directory danu:/tmp/cvs-serv17518/lib-imap

Modified Files:
	imap-envelope.c imap-envelope.h 
Log Message:
SEARCHing headers with "" value should always match if the header is found.
Changed imap_envelope_parse() so that it's possible to differentiate NIL
from "".



Index: imap-envelope.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-envelope.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- imap-envelope.c	2 Jan 2003 08:09:27 -0000	1.18
+++ imap-envelope.c	2 Jan 2003 09:06:33 -0000	1.19
@@ -233,16 +233,19 @@
 	return t_strdup(imap_arg_string(&list->args[2]));
 }
 
-static const char *
-imap_envelope_parse_arg(ImapArg *arg, ImapEnvelopeField field,
-			const char *envelope, ImapEnvelopeResult result)
+static int imap_envelope_parse_arg(ImapArg *arg, ImapEnvelopeField field,
+				   const char *envelope,
+				   ImapEnvelopeResult result_type,
+				   const char **result)
 {
 	const char *value = NULL;
 
-	if (arg->type == IMAP_ARG_NIL)
-		return "";
+	if (arg->type == IMAP_ARG_NIL) {
+		*result = NULL;
+		return TRUE;
+	}
 
-	switch (result) {
+	switch (result_type) {
 	case IMAP_ENVELOPE_RESULT_STRING:
 		if (field >= IMAP_ENVELOPE_FROM && field <= IMAP_ENVELOPE_BCC)
 			value = imap_envelope_parse_address(arg);
@@ -256,21 +259,22 @@
 		break;
 	}
 
-	if (value == NULL) {
+	*result = value;
+	if (value != NULL)
+		return TRUE;
+	else {
 		i_error("Invalid field %u in IMAP envelope: %s",
 			field, envelope);
+		return FALSE;
 	}
-
-	return value;
 }
 
-const char *imap_envelope_parse(const char *envelope, ImapEnvelopeField field,
-				ImapEnvelopeResult result)
+int imap_envelope_parse(const char *envelope, ImapEnvelopeField field,
+			ImapEnvelopeResult result_type, const char **result)
 {
 	IStream *input;
 	ImapParser *parser;
 	ImapArg *args;
-	const char *value;
 	int ret;
 
 	i_assert(field < IMAP_ENVELOPE_FIELDS);
@@ -282,14 +286,15 @@
 	(void)i_stream_read(input);
 	ret = imap_parser_read_args(parser, field+1, 0, &args);
 	if (ret > (int)field) {
-		value = imap_envelope_parse_arg(&args[field], field,
-						envelope, result);
+		ret = imap_envelope_parse_arg(&args[field], field,
+					      envelope, result_type, result);
 	} else {
 		i_error("Error parsing IMAP envelope: %s", envelope);
-		value = NULL;
+		*result = NULL;
+		ret = FALSE;
 	}
 
 	imap_parser_destroy(parser);
 	i_stream_unref(input);
-	return value;
+	return ret;
 }

Index: imap-envelope.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-envelope.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- imap-envelope.h	21 Dec 2002 22:02:58 -0000	1.5
+++ imap-envelope.h	2 Jan 2003 09:06:33 -0000	1.6
@@ -35,9 +35,9 @@
 /* Return envelope. */
 const char *imap_envelope_get_part_data(MessagePartEnvelopeData *data);
 
-/* Parse envelope and return specified field unquoted, or NULL if error
-   occured. NILs are returned as "". */
-const char *imap_envelope_parse(const char *envelope, ImapEnvelopeField field,
-				ImapEnvelopeResult result);
+/* Parse envelope and store specified field to result. NIL is stored as NULL.
+   Returns TRUE if successful. */
+int imap_envelope_parse(const char *envelope, ImapEnvelopeField field,
+			ImapEnvelopeResult result_type, const char **result);
 
 #endif




More information about the dovecot-cvs mailing list