[gmime] Replace g_mime_parser_get/set_scan_from() with get/set_format()
- From: Jeffrey Stedfast <fejj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gmime] Replace g_mime_parser_get/set_scan_from() with get/set_format()
- Date: Mon, 13 Mar 2017 00:50:00 +0000 (UTC)
commit 94b56e9d33d76b63c409a6d4ec0eef5963862189
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date: Sun Mar 12 20:21:57 2017 -0400
Replace g_mime_parser_get/set_scan_from() with get/set_format()
PORTING | 3 ++
docs/reference/changes-3.0.sgml | 1 +
docs/reference/gmime-sections.txt | 4 +-
examples/imap-example.c | 11 +++-----
gmime/gmime-parser.c | 52 +++++++++++++++++-------------------
gmime/gmime-parser.h | 17 ++++++++++-
tests/test-mbox.c | 4 +-
7 files changed, 52 insertions(+), 40 deletions(-)
---
diff --git a/PORTING b/PORTING
index f25c199..f3d2944 100644
--- a/PORTING
+++ b/PORTING
@@ -125,6 +125,9 @@ Porting from GMime 2.6 to GMime 3.0
argument nor does it return int. Instead, this function now returns a newly
allocated GMimeMultipartSigned.
+- g_mime_parser_[get,set]_scan_from() have been replaced by
+ g_mime_parser_[get,set]_format() which takes a GMimeFormat argument.
+
Porting from GMime 2.4 to GMime 2.6
-----------------------------------
diff --git a/docs/reference/changes-3.0.sgml b/docs/reference/changes-3.0.sgml
index 76ade30..e171ccc 100644
--- a/docs/reference/changes-3.0.sgml
+++ b/docs/reference/changes-3.0.sgml
@@ -50,6 +50,7 @@
<listitem><para><function>g_mime_part_new()</function> now returns a GMimePart with a Content-Type of
"application/octet-stream" instead of "text/plain" since there is now a GMimeTextPart who's
<function>g_mime_text_part_new()</function> returns a GMimeTextPart with a Content-Type of
"text/plain".</para></listitem>
<listitem><para><function>g_mime_part_get_content_object()</function> has been renamed to
<function>g_mime_part_get_content()</function>.</para></listitem>
<listitem><para><function>g_mime_part_set_content_object()</function> has been renamed to
<function>g_mime_part_set_content()</function>.</para></listitem>
+ <listitem><para><function>g_mime_parser_get_scan_from()</function> and
<function>g_mime_parser_set_scan_from()</function> have been replaced by
<function>g_mime_parser_get_format()</function> and <function>g_mime_parser_get_format()</function> which
take a GMimeFormat argument.</para></listitem>
</itemizedlist>
</refsect1>
</refentry>
diff --git a/docs/reference/gmime-sections.txt b/docs/reference/gmime-sections.txt
index 02bf83c..9906d15 100644
--- a/docs/reference/gmime-sections.txt
+++ b/docs/reference/gmime-sections.txt
@@ -1159,8 +1159,8 @@ g_mime_parser_new_with_stream
g_mime_parser_init_with_stream
g_mime_parser_get_persist_stream
g_mime_parser_set_persist_stream
-g_mime_parser_get_scan_from
-g_mime_parser_set_scan_from
+g_mime_parser_get_format
+g_mime_parser_set_format
g_mime_parser_get_respect_content_length
g_mime_parser_set_respect_content_length
g_mime_parser_set_header_regex
diff --git a/examples/imap-example.c b/examples/imap-example.c
index 3a1ff46..9026429 100644
--- a/examples/imap-example.c
+++ b/examples/imap-example.c
@@ -766,7 +766,6 @@ reconstruct_message_part (GMimeMessagePart *msgpart, const char *uid, const char
stream = g_mime_stream_fs_new (fd);
parser = g_mime_parser_new_with_stream (stream);
- g_mime_parser_set_scan_from (parser, FALSE);
g_object_unref (stream);
message = g_mime_parser_construct_message (parser);
@@ -821,7 +820,6 @@ reconstruct_multipart (GMimeMultipart *multipart, struct _bodystruct *body,
stream = g_mime_stream_fs_new (fd);
parser = g_mime_parser_new_with_stream (stream);
- g_mime_parser_set_scan_from (parser, FALSE);
g_object_unref (stream);
subpart = g_mime_parser_construct_part (parser);
@@ -861,7 +859,6 @@ reconstruct_message (const char *uid)
stream = g_mime_stream_fs_new (fd);
parser = g_mime_parser_new_with_stream (stream);
- g_mime_parser_set_scan_from (parser, FALSE);
g_object_unref (stream);
/* constructs message object and toplevel mime part (although
@@ -916,7 +913,7 @@ reconstruct_message (const char *uid)
int main (int argc, char **argv)
{
- gboolean scan_from = FALSE;
+ GMimeFormat format = GMIME_FORMAT_MESSAGE;
GMimeMessage *message;
GMimeParser *parser;
GMimeStream *stream;
@@ -928,8 +925,8 @@ int main (int argc, char **argv)
g_mime_init ();
- if (!strcmp (argv[i], "-f")) {
- scan_from = TRUE;
+ if (!strcmp (argv[i], "--mbox")) {
+ format = GMIME_FORMAT_MBOX;
i++;
}
@@ -939,7 +936,7 @@ int main (int argc, char **argv)
stream = g_mime_stream_fs_new (fd);
parser = g_mime_parser_new_with_stream (stream);
- g_mime_parser_set_scan_from (parser, scan_from);
+ g_mime_parser_set_format (parser, format);
g_object_unref (stream);
message = g_mime_parser_construct_message (parser);
diff --git a/gmime/gmime-parser.c b/gmime/gmime-parser.c
index 5ee14c8..77a7863 100644
--- a/gmime/gmime-parser.c
+++ b/gmime/gmime-parser.c
@@ -122,6 +122,7 @@ enum {
struct _GMimeParserPrivate {
GMimeStream *stream;
+ GMimeFormat format;
gint64 offset;
@@ -166,10 +167,9 @@ struct _GMimeParserPrivate {
short int state;
- unsigned short int unused:10;
+ unsigned short int unused:11;
unsigned short int midline:1;
unsigned short int seekable:1;
- unsigned short int scan_from:1;
unsigned short int have_regex:1;
unsigned short int persist_stream:1;
unsigned short int respect_content_length:1;
@@ -308,7 +308,8 @@ g_mime_parser_init (GMimeParser *parser, GMimeParserClass *klass)
parser->priv->respect_content_length = FALSE;
parser->priv->persist_stream = TRUE;
parser->priv->have_regex = FALSE;
- parser->priv->scan_from = FALSE;
+
+ parser->priv->format = GMIME_FORMAT_MESSAGE;
#if defined (HAVE_GLIB_REGEX)
parser->priv->regex = NULL;
@@ -520,38 +521,35 @@ g_mime_parser_set_persist_stream (GMimeParser *parser, gboolean persist)
/**
- * g_mime_parser_get_scan_from:
+ * g_mime_parser_get_format:
* @parser: a #GMimeParser context
*
- * Gets whether or not @parser is set to scan mbox-style From-lines.
+ * Gets the format that the parser is set to parse.
*
- * Returns: whether or not @parser is set to scan mbox-style
- * From-lines.
+ * Returns: the format that the parser is set to parse.
**/
-gboolean
-g_mime_parser_get_scan_from (GMimeParser *parser)
+GMimeFormat
+g_mime_parser_get_format (GMimeParser *parser)
{
- g_return_val_if_fail (GMIME_IS_PARSER (parser), FALSE);
+ g_return_val_if_fail (GMIME_IS_PARSER (parser), GMIME_FORMAT_MESSAGE);
- return parser->priv->scan_from;
+ return parser->priv->format;
}
/**
- * g_mime_parser_set_scan_from:
+ * g_mime_parser_set_format:
* @parser: a #GMimeParser context
- * @scan_from: %TRUE to scan From-lines or %FALSE otherwise
+ * @format: a #GMimeFormat
*
- * Sets whether or not @parser should scan mbox-style From-lines.
- *
- * By default, this feature is disabled.
+ * Sets the format that the parser should expect the stream to be in.
**/
void
-g_mime_parser_set_scan_from (GMimeParser *parser, gboolean scan_from)
+g_mime_parser_set_format (GMimeParser *parser, GMimeFormat format)
{
g_return_if_fail (GMIME_IS_PARSER (parser));
- parser->priv->scan_from = scan_from ? 1 : 0;
+ parser->priv->format = format;
}
@@ -1064,7 +1062,7 @@ parser_step_headers (GMimeParser *parser)
}
if (!valid) {
- if (priv->scan_from && (inptr - start) == 4
+ if (priv->format == GMIME_FORMAT_MBOX && (inptr - start) == 4
&& !strncmp (start, "From ", 5))
goto next_message;
@@ -1272,7 +1270,7 @@ parser_step (GMimeParser *parser)
case GMIME_PARSER_STATE_INIT:
priv->message_headers_begin = -1;
priv->message_headers_end = -1;
- if (priv->scan_from)
+ if (priv->format == GMIME_FORMAT_MBOX)
priv->state = GMIME_PARSER_STATE_FROM;
else
priv->state = GMIME_PARSER_STATE_MESSAGE_HEADERS;
@@ -1322,8 +1320,8 @@ enum {
g_byte_array_append (content, (unsigned char *) start, len); \
} G_STMT_END
-#define possible_boundary(scan_from, start, len) \
- ((scan_from && len >= 5 && !strncmp (start, "From ", 5)) || \
+#define possible_boundary(is_mbox, start, len) \
+ ((is_mbox && len >= 5 && !strncmp (start, "From ", 5)) || \
(len >= 2 && (start[0] == '-' && start[1] == '-')))
static gboolean
@@ -1361,7 +1359,7 @@ check_boundary (struct _GMimeParserPrivate *priv, const char *start, size_t len)
if (len > 0 && start[len - 1] == '\r')
len--;
- if (possible_boundary (priv->scan_from, start, len)) {
+ if (possible_boundary (priv->format == GMIME_FORMAT_MBOX, start, len)) {
BoundaryStack *s;
d(printf ("checking boundary '%.*s'\n", len, start));
@@ -1957,7 +1955,7 @@ parser_construct_message (GMimeParser *parser, GMimeParserOptions *options)
header = header->next;
}
- if (priv->scan_from) {
+ if (priv->format == GMIME_FORMAT_MBOX) {
parser_push_boundary (parser, MBOX_BOUNDARY);
if (priv->respect_content_length && content_length < ULONG_MAX)
priv->bounds->content_end = parser_offset (priv, NULL) + content_length;
@@ -1972,7 +1970,7 @@ parser_construct_message (GMimeParser *parser, GMimeParserOptions *options)
content_type_destroy (content_type);
message->mime_part = object;
- if (priv->scan_from) {
+ if (priv->format == GMIME_FORMAT_MBOX) {
priv->state = GMIME_PARSER_STATE_FROM;
parser_pop_boundary (parser);
}
@@ -2035,7 +2033,7 @@ g_mime_parser_get_from (GMimeParser *parser)
g_return_val_if_fail (GMIME_IS_PARSER (parser), NULL);
priv = parser->priv;
- if (!priv->scan_from)
+ if (priv->format != GMIME_FORMAT_MBOX)
return NULL;
if (priv->from_line->len)
@@ -2063,7 +2061,7 @@ g_mime_parser_get_from_offset (GMimeParser *parser)
g_return_val_if_fail (GMIME_IS_PARSER (parser), -1);
priv = parser->priv;
- if (!priv->scan_from)
+ if (priv->format != GMIME_FORMAT_MBOX)
return -1;
return priv->from_offset;
diff --git a/gmime/gmime-parser.h b/gmime/gmime-parser.h
index 6440cf1..6e22436 100644
--- a/gmime/gmime-parser.h
+++ b/gmime/gmime-parser.h
@@ -46,6 +46,19 @@ typedef struct _GMimeParserClass GMimeParserClass;
/**
+ * GMimeFormat:
+ * @GMIME_FORMAT_ENTITY: The stream contains a single message.
+ * @GMIME_FORMAT_MBOX: The stream is in the UNIX mbox format.
+ *
+ * An enum of formats.
+ **/
+typedef enum {
+ GMIME_FORMAT_MESSAGE,
+ GMIME_FORMAT_MBOX
+} GMimeFormat;
+
+
+/**
* GMimeParser:
* @parent_object: parent #GObject
* @priv: private parser state
@@ -90,8 +103,8 @@ void g_mime_parser_init_with_stream (GMimeParser *parser, GMimeStream *stream);
gboolean g_mime_parser_get_persist_stream (GMimeParser *parser);
void g_mime_parser_set_persist_stream (GMimeParser *parser, gboolean persist);
-gboolean g_mime_parser_get_scan_from (GMimeParser *parser);
-void g_mime_parser_set_scan_from (GMimeParser *parser, gboolean scan_from);
+GMimeFormat g_mime_parser_get_format (GMimeParser *parser);
+void g_mime_parser_set_format (GMimeParser *parser, GMimeFormat format);
gboolean g_mime_parser_get_respect_content_length (GMimeParser *parser);
void g_mime_parser_set_respect_content_length (GMimeParser *parser, gboolean respect_content_length);
diff --git a/tests/test-mbox.c b/tests/test-mbox.c
index 95f52ef..29c7a59 100644
--- a/tests/test-mbox.c
+++ b/tests/test-mbox.c
@@ -348,7 +348,7 @@ int main (int argc, char **argv)
parser = g_mime_parser_new_with_stream (istream);
g_mime_parser_set_persist_stream (parser, TRUE);
- g_mime_parser_set_scan_from (parser, TRUE);
+ g_mime_parser_set_format (parser, GMIME_FORMAT_MBOX);
if (strstr (dent, "content-length") != NULL)
g_mime_parser_set_respect_content_length (parser, TRUE);
@@ -406,7 +406,7 @@ int main (int argc, char **argv)
goto exit;
parser = g_mime_parser_new_with_stream (istream);
- g_mime_parser_set_scan_from (parser, TRUE);
+ g_mime_parser_set_format (parser, GMIME_FORMAT_MBOX);
#ifdef ENABLE_MBOX_MATCH
tmp = g_strdup ("./tmp/mbox-test.XXXXXX");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]