diff --git a/lib/mu-msg-part.c b/lib/mu-msg-part.c
index 72d0589f..5958820d 100644
--- a/lib/mu-msg-part.c
+++ b/lib/mu-msg-part.c
@@ -464,8 +464,7 @@ mu_msg_part_filepath (MuMsg *msg, const char* targetdir, guint partidx,
return NULL;
if (!(mobj = find_part (msg, partidx))) {
- mu_util_g_set_error (err,
- MU_ERROR_GMIME,
+ mu_util_g_set_error (err,MU_ERROR_GMIME,
"cannot find part %u", partidx);
return NULL;
}
@@ -477,7 +476,7 @@ mu_msg_part_filepath (MuMsg *msg, const char* targetdir, guint partidx,
* components */
fname = g_path_get_basename (fname);
else
- fname = g_strdup_printf ("%x-part-%u",
+ fname = g_strdup_printf ("%x-part-%u",
g_str_hash (mu_msg_get_path (msg)),
partidx);
} else if (GMIME_IS_MESSAGE_PART(mobj))
@@ -485,8 +484,8 @@ mu_msg_part_filepath (MuMsg *msg, const char* targetdir, guint partidx,
(g_mime_message_part_get_message
((GMimeMessagePart*)mobj));
else {
- g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_GMIME,
- "part %u cannot be saved", partidx);
+ mu_util_g_set_error (err, MU_ERROR_GMIME,
+ "part %u cannot be saved", partidx);
return NULL;
}
diff --git a/lib/mu-msg-sexp.c b/lib/mu-msg-sexp.c
index e252b88b..50f22556 100644
--- a/lib/mu-msg-sexp.c
+++ b/lib/mu-msg-sexp.c
@@ -255,22 +255,40 @@ sig_verdict (GSList *sig_infos)
}
-static void
-each_part (MuMsg *msg, MuMsgPart *part, PartInfo *pinfo)
+static char*
+get_part_filename (MuMsgPart *part)
{
const char *fname;
- char *name, *tmp;
- char *tmpfile;
+ char *name;
+ const char *ctype, *csubtype;
- if (!(fname = mu_msg_part_file_name (part)))
+ ctype = part->type;
+ csubtype = part->subtype;
+ if (!ctype || !csubtype) {
+ ctype = "application";
+ csubtype = "octet-stream";
+ }
+
+ fname = mu_msg_part_file_name (part);
+ if (!fname)
fname = mu_msg_part_description (part);
+
if (fname)
name = mu_str_escape_c_literal (fname, TRUE);
else
name = g_strdup_printf ("\"%s-%s-%d\"",
- elvis (part->type, "application"),
- elvis (part->subtype, "octet-stream"),
- part->index);
+ ctype, csubtype, part->index);
+ return name;
+}
+
+
+static void
+each_part (MuMsg *msg, MuMsgPart *part, PartInfo *pinfo)
+{
+ char *name, *tmp;
+ char *tmpfile;
+
+ name = get_part_filename (part);
tmpfile = NULL;
if (pinfo->want_images && g_ascii_strcasecmp (part->type, "image") == 0) {
@@ -344,6 +362,13 @@ append_sexp_thread_info (GString *gstr, const MuMsgIterThreadInfo *ti)
" :has-child t" : "");
}
+static void
+append_non_headers_only_attr (GString *gstr, MuMsg *msg, MuMsgOptions opts)
+{
+ append_sexp_message_file_attr (gstr, msg);
+ append_sexp_parts (gstr, msg, opts);
+}
+
char*
mu_msg_to_sexp (MuMsg *msg, unsigned docid, const MuMsgIterThreadInfo *ti,
@@ -356,9 +381,8 @@ mu_msg_to_sexp (MuMsg *msg, unsigned docid, const MuMsgIterThreadInfo *ti,
g_return_val_if_fail (!((opts & MU_MSG_OPTION_HEADERS_ONLY) &&
(opts & MU_MSG_OPTION_EXTRACT_IMAGES)),
NULL);
-
- gstr = g_string_sized_new ((opts & MU_MSG_OPTION_HEADERS_ONLY) ?
- 1024 : 8192);
+ gstr = g_string_sized_new
+ ((opts & MU_MSG_OPTION_HEADERS_ONLY) ? 1024 : 8192);
g_string_append (gstr, "(\n");
if (docid != 0)
@@ -374,23 +398,20 @@ mu_msg_to_sexp (MuMsg *msg, unsigned docid, const MuMsgIterThreadInfo *ti,
g_string_append_printf (gstr,"\t:date (%u %u 0)\n", (unsigned)(t >> 16),
(unsigned)(t & 0xffff));
g_string_append_printf (gstr, "\t:size %u\n",
- (unsigned) mu_msg_get_size (msg));
+ (unsigned)mu_msg_get_size (msg));
append_sexp_attr (gstr, "message-id", mu_msg_get_msgid (msg));
append_sexp_attr (gstr, "path", mu_msg_get_path (msg));
append_sexp_attr (gstr, "maildir", mu_msg_get_maildir (msg));
g_string_append_printf (gstr, "\t:priority %s\n",
mu_msg_prio_name(mu_msg_get_prio(msg)));
-
append_sexp_flags (gstr, msg);
/* headers are retrieved from the database, views from the message file
* file attr things can only be gotten from the file (ie., mu
* view), not from the database (mu find). */
- if (!(opts & MU_MSG_OPTION_HEADERS_ONLY)) {
- append_sexp_message_file_attr (gstr, msg);
- append_sexp_parts (gstr, msg, opts);
- }
+ if (!(opts & MU_MSG_OPTION_HEADERS_ONLY))
+ append_non_headers_only_attr (gstr, msg, opts);
/* note, some of the contacts info comes from the file, soe
* this has to be after the previous */
diff --git a/mu/mu-cmd-find.c b/mu/mu-cmd-find.c
index 54a81637..8cb6d71b 100644
--- a/mu/mu-cmd-find.c
+++ b/mu/mu-cmd-find.c
@@ -534,6 +534,40 @@ output_xml (MuMsg *msg, MuMsgIter *iter, MuConfig *opts, GError **err)
}
+static OutputFunc*
+output_prepare (MuConfig *opts, GError **err)
+{
+ switch (opts->format) {
+ case MU_CONFIG_FORMAT_EXEC:
+ return exec_cmd;
+ case MU_CONFIG_FORMAT_LINKS:
+ if (!prepare_links (opts, err))
+ return NULL;
+ else
+ return output_link;
+ case MU_CONFIG_FORMAT_PLAIN:
+ return output_plain;
+ case MU_CONFIG_FORMAT_XML:
+ g_print ("\n");
+ g_print ("\n");
+ return output_xml;
+ case MU_CONFIG_FORMAT_SEXP:
+ return output_sexp;
+
+ default:
+ g_return_val_if_reached (NULL);
+ return NULL;
+ }
+}
+
+static void
+output_finish (MuConfig *opts)
+{
+ if (opts->format == MU_CONFIG_FORMAT_XML)
+ g_print ("\n");
+}
+
+
static gboolean
output_query_results (MuMsgIter *iter, MuConfig *opts, GError **err)
{
@@ -541,22 +575,9 @@ output_query_results (MuMsgIter *iter, MuConfig *opts, GError **err)
gboolean rv;
OutputFunc *output_func;
- switch (opts->format) {
- case MU_CONFIG_FORMAT_EXEC: output_func = exec_cmd; break;
- case MU_CONFIG_FORMAT_LINKS:
- if (!prepare_links (opts, err))
- return FALSE;
- output_func = output_link;
- break;
- case MU_CONFIG_FORMAT_PLAIN: output_func = output_plain; break;
- case MU_CONFIG_FORMAT_XML: output_func = output_xml;
- g_print ("\n");
- g_print ("\n");
- break;
- case MU_CONFIG_FORMAT_SEXP: output_func = output_sexp; break;
- break;
- default: g_assert_not_reached ();
- }
+ output_func = output_prepare (opts, err);
+ if (!output_func)
+ return FALSE;
for (count = 0, rv = TRUE; !mu_msg_iter_is_done(iter);
mu_msg_iter_next (iter)) {
@@ -574,8 +595,7 @@ output_query_results (MuMsgIter *iter, MuConfig *opts, GError **err)
++count;
}
- if (opts->format == MU_CONFIG_FORMAT_XML)
- g_print ("\n");
+ output_finish (opts);
if (rv && count == 0) {
mu_util_g_set_error (err, MU_ERROR_NO_MATCHES,
@@ -645,15 +665,15 @@ format_params_valid (MuConfig *opts, GError **err)
case MU_CONFIG_FORMAT_XML:
case MU_CONFIG_FORMAT_XQUERY:
if (opts->exec) {
- mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
- "--exec cannot be combined with --format");
+ mu_util_g_set_error
+ (err, MU_ERROR_IN_PARAMETERS,
+ "--exec and --format cannot be combined");
return FALSE;
}
break;
- default:
- mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
- "invalid output format %s",
- opts->formatstr ? opts->formatstr : "");
+ default: mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
+ "invalid output format %s",
+ opts->formatstr ? opts->formatstr : "");
return FALSE;
}
@@ -665,7 +685,7 @@ format_params_valid (MuConfig *opts, GError **err)
if (opts->linksdir && opts->format != MU_CONFIG_FORMAT_LINKS) {
mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
- "--linksdir is only valid with --format=links");
+ "--linksdir is only valid with --format=links");
return FALSE;
}
diff --git a/mu/mu-cmd-server.c b/mu/mu-cmd-server.c
index 53e71dab..8cfbf747 100644
--- a/mu/mu-cmd-server.c
+++ b/mu/mu-cmd-server.c
@@ -975,9 +975,8 @@ cmd_index (ServerContext *ctx, GSList *args, GError **err)
MuError rv;
GET_STRING_OR_ERROR_RETURN (args, "path", &path, err);
- set_my_addresses (ctx->store,
- get_string_from_args (args, "my-addresses",
- TRUE, NULL));
+ set_my_addresses (ctx->store, get_string_from_args
+ (args, "my-addresses", TRUE, NULL));
index = mu_index_new (ctx->store, err);
if (!index) {
@@ -1004,7 +1003,6 @@ cmd_index (ServerContext *ctx, GSList *args, GError **err)
print_expr ("(:info index :status complete "
":processed %u :updated %u :cleaned-up %u)",
stats._processed, stats._updated, stats2._cleaned_up);
-
leave:
mu_index_destroy (index);
return MU_OK;