* fixes for 'make line35' (small function refactoring)

This commit is contained in:
djcb
2012-07-20 11:54:37 +03:00
parent ff2e39b629
commit c240e6c17f
4 changed files with 89 additions and 51 deletions

View File

@ -464,8 +464,7 @@ mu_msg_part_filepath (MuMsg *msg, const char* targetdir, guint partidx,
return NULL; return NULL;
if (!(mobj = find_part (msg, partidx))) { if (!(mobj = find_part (msg, partidx))) {
mu_util_g_set_error (err, mu_util_g_set_error (err,MU_ERROR_GMIME,
MU_ERROR_GMIME,
"cannot find part %u", partidx); "cannot find part %u", partidx);
return NULL; return NULL;
} }
@ -485,7 +484,7 @@ mu_msg_part_filepath (MuMsg *msg, const char* targetdir, guint partidx,
(g_mime_message_part_get_message (g_mime_message_part_get_message
((GMimeMessagePart*)mobj)); ((GMimeMessagePart*)mobj));
else { else {
g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_GMIME, mu_util_g_set_error (err, MU_ERROR_GMIME,
"part %u cannot be saved", partidx); "part %u cannot be saved", partidx);
return NULL; return NULL;
} }

View File

@ -255,22 +255,40 @@ sig_verdict (GSList *sig_infos)
} }
static void static char*
each_part (MuMsg *msg, MuMsgPart *part, PartInfo *pinfo) get_part_filename (MuMsgPart *part)
{ {
const char *fname; const char *fname;
char *name, *tmp; char *name;
char *tmpfile; 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); fname = mu_msg_part_description (part);
if (fname) if (fname)
name = mu_str_escape_c_literal (fname, TRUE); name = mu_str_escape_c_literal (fname, TRUE);
else else
name = g_strdup_printf ("\"%s-%s-%d\"", name = g_strdup_printf ("\"%s-%s-%d\"",
elvis (part->type, "application"), ctype, csubtype, part->index);
elvis (part->subtype, "octet-stream"), return name;
part->index); }
static void
each_part (MuMsg *msg, MuMsgPart *part, PartInfo *pinfo)
{
char *name, *tmp;
char *tmpfile;
name = get_part_filename (part);
tmpfile = NULL; tmpfile = NULL;
if (pinfo->want_images && g_ascii_strcasecmp (part->type, "image") == 0) { 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" : ""); " :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* char*
mu_msg_to_sexp (MuMsg *msg, unsigned docid, const MuMsgIterThreadInfo *ti, 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) && g_return_val_if_fail (!((opts & MU_MSG_OPTION_HEADERS_ONLY) &&
(opts & MU_MSG_OPTION_EXTRACT_IMAGES)), (opts & MU_MSG_OPTION_EXTRACT_IMAGES)),
NULL); NULL);
gstr = g_string_sized_new
gstr = g_string_sized_new ((opts & MU_MSG_OPTION_HEADERS_ONLY) ? ((opts & MU_MSG_OPTION_HEADERS_ONLY) ? 1024 : 8192);
1024 : 8192);
g_string_append (gstr, "(\n"); g_string_append (gstr, "(\n");
if (docid != 0) 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), g_string_append_printf (gstr,"\t:date (%u %u 0)\n", (unsigned)(t >> 16),
(unsigned)(t & 0xffff)); (unsigned)(t & 0xffff));
g_string_append_printf (gstr, "\t:size %u\n", 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, "message-id", mu_msg_get_msgid (msg));
append_sexp_attr (gstr, "path", mu_msg_get_path (msg)); append_sexp_attr (gstr, "path", mu_msg_get_path (msg));
append_sexp_attr (gstr, "maildir", mu_msg_get_maildir (msg)); append_sexp_attr (gstr, "maildir", mu_msg_get_maildir (msg));
g_string_append_printf (gstr, "\t:priority %s\n", g_string_append_printf (gstr, "\t:priority %s\n",
mu_msg_prio_name(mu_msg_get_prio(msg))); mu_msg_prio_name(mu_msg_get_prio(msg)));
append_sexp_flags (gstr, msg); append_sexp_flags (gstr, msg);
/* headers are retrieved from the database, views from the message file /* headers are retrieved from the database, views from the message file
* file attr things can only be gotten from the file (ie., mu * file attr things can only be gotten from the file (ie., mu
* view), not from the database (mu find). */ * view), not from the database (mu find). */
if (!(opts & MU_MSG_OPTION_HEADERS_ONLY)) { if (!(opts & MU_MSG_OPTION_HEADERS_ONLY))
append_sexp_message_file_attr (gstr, msg); append_non_headers_only_attr (gstr, msg, opts);
append_sexp_parts (gstr, msg, opts);
}
/* note, some of the contacts info comes from the file, soe /* note, some of the contacts info comes from the file, soe
* this has to be after the previous */ * this has to be after the previous */

View File

@ -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 ("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
g_print ("<messages>\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 ("</messages>\n");
}
static gboolean static gboolean
output_query_results (MuMsgIter *iter, MuConfig *opts, GError **err) output_query_results (MuMsgIter *iter, MuConfig *opts, GError **err)
{ {
@ -541,22 +575,9 @@ output_query_results (MuMsgIter *iter, MuConfig *opts, GError **err)
gboolean rv; gboolean rv;
OutputFunc *output_func; OutputFunc *output_func;
switch (opts->format) { output_func = output_prepare (opts, err);
case MU_CONFIG_FORMAT_EXEC: output_func = exec_cmd; break; if (!output_func)
case MU_CONFIG_FORMAT_LINKS:
if (!prepare_links (opts, err))
return FALSE; 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 ("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
g_print ("<messages>\n");
break;
case MU_CONFIG_FORMAT_SEXP: output_func = output_sexp; break;
break;
default: g_assert_not_reached ();
}
for (count = 0, rv = TRUE; !mu_msg_iter_is_done(iter); for (count = 0, rv = TRUE; !mu_msg_iter_is_done(iter);
mu_msg_iter_next (iter)) { mu_msg_iter_next (iter)) {
@ -574,8 +595,7 @@ output_query_results (MuMsgIter *iter, MuConfig *opts, GError **err)
++count; ++count;
} }
if (opts->format == MU_CONFIG_FORMAT_XML) output_finish (opts);
g_print ("</messages>\n");
if (rv && count == 0) { if (rv && count == 0) {
mu_util_g_set_error (err, MU_ERROR_NO_MATCHES, mu_util_g_set_error (err, MU_ERROR_NO_MATCHES,
@ -645,13 +665,13 @@ format_params_valid (MuConfig *opts, GError **err)
case MU_CONFIG_FORMAT_XML: case MU_CONFIG_FORMAT_XML:
case MU_CONFIG_FORMAT_XQUERY: case MU_CONFIG_FORMAT_XQUERY:
if (opts->exec) { if (opts->exec) {
mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS, mu_util_g_set_error
"--exec cannot be combined with --format"); (err, MU_ERROR_IN_PARAMETERS,
"--exec and --format cannot be combined");
return FALSE; return FALSE;
} }
break; break;
default: default: mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
"invalid output format %s", "invalid output format %s",
opts->formatstr ? opts->formatstr : "<none>"); opts->formatstr ? opts->formatstr : "<none>");
return FALSE; return FALSE;

View File

@ -975,9 +975,8 @@ cmd_index (ServerContext *ctx, GSList *args, GError **err)
MuError rv; MuError rv;
GET_STRING_OR_ERROR_RETURN (args, "path", &path, err); GET_STRING_OR_ERROR_RETURN (args, "path", &path, err);
set_my_addresses (ctx->store, set_my_addresses (ctx->store, get_string_from_args
get_string_from_args (args, "my-addresses", (args, "my-addresses", TRUE, NULL));
TRUE, NULL));
index = mu_index_new (ctx->store, err); index = mu_index_new (ctx->store, err);
if (!index) { if (!index) {
@ -1004,7 +1003,6 @@ cmd_index (ServerContext *ctx, GSList *args, GError **err)
print_expr ("(:info index :status complete " print_expr ("(:info index :status complete "
":processed %u :updated %u :cleaned-up %u)", ":processed %u :updated %u :cleaned-up %u)",
stats._processed, stats._updated, stats2._cleaned_up); stats._processed, stats._updated, stats2._cleaned_up);
leave: leave:
mu_index_destroy (index); mu_index_destroy (index);
return MU_OK; return MU_OK;