* crypto: update for crypto api changes
This commit is contained in:
@ -223,9 +223,28 @@ get_temp_file (MuMsg *msg, unsigned index)
|
||||
}
|
||||
|
||||
|
||||
static gchar*
|
||||
get_temp_file_maybe (MuMsg *msg, MuMsgPart *part, MuMsgOptions opts)
|
||||
{
|
||||
char *tmp, *tmpfile;
|
||||
|
||||
if (!(opts & MU_MSG_OPTION_EXTRACT_IMAGES) ||
|
||||
g_ascii_strcasecmp (part->type, "image") != 0)
|
||||
return NULL;
|
||||
|
||||
tmp = get_temp_file (msg, part->index);
|
||||
if (!tmp)
|
||||
return NULL;
|
||||
|
||||
tmpfile = mu_str_escape_c_literal (tmp, TRUE);
|
||||
g_free (tmp);
|
||||
return tmpfile;
|
||||
}
|
||||
|
||||
|
||||
struct _PartInfo {
|
||||
char *parts;
|
||||
gboolean want_images;
|
||||
MuMsgOptions opts;
|
||||
};
|
||||
typedef struct _PartInfo PartInfo;
|
||||
|
||||
@ -331,15 +350,7 @@ each_part (MuMsg *msg, MuMsgPart *part, PartInfo *pinfo)
|
||||
|
||||
name = get_part_filename (part);
|
||||
|
||||
tmpfile = NULL;
|
||||
if (pinfo->want_images && g_ascii_strcasecmp (part->type, "image") == 0) {
|
||||
char *tmp;
|
||||
if ((tmp = get_temp_file (msg, part->index))) {
|
||||
tmpfile = mu_str_escape_c_literal (tmp, TRUE);
|
||||
g_free (tmp);
|
||||
}
|
||||
}
|
||||
|
||||
tmpfile = get_temp_file_maybe (msg, part, pinfo->opts);
|
||||
parttype = get_part_type_string (part->part_type);
|
||||
|
||||
tmp = g_strdup_printf
|
||||
@ -356,7 +367,6 @@ each_part (MuMsg *msg, MuMsgPart *part, PartInfo *pinfo)
|
||||
sig_verdict (part->sig_infos));
|
||||
|
||||
g_free (pinfo->parts);
|
||||
|
||||
pinfo->parts = tmp;
|
||||
}
|
||||
|
||||
@ -367,7 +377,7 @@ append_sexp_parts (GString *gstr, MuMsg *msg, MuMsgOptions opts)
|
||||
PartInfo pinfo;
|
||||
|
||||
pinfo.parts = NULL;
|
||||
pinfo.want_images = opts & MU_MSG_OPTION_EXTRACT_IMAGES;
|
||||
pinfo.opts = opts;
|
||||
|
||||
mu_msg_part_foreach (msg, (MuMsgPartForeachFunc)each_part,
|
||||
&pinfo, opts);
|
||||
|
||||
@ -385,13 +385,13 @@ struct PartData {
|
||||
|
||||
|
||||
static gboolean
|
||||
maybe_index_text_part (MuMsgPart *part, PartData *pdata)
|
||||
maybe_index_text_part (MuMsg *msg, MuMsgPart *part, PartData *pdata)
|
||||
{
|
||||
gboolean err;
|
||||
char *txt, *norm;
|
||||
Xapian::TermGenerator termgen;
|
||||
|
||||
txt = mu_msg_part_get_text (part, &err);
|
||||
txt = mu_msg_part_get_text (msg, part, &err);
|
||||
if (!txt || err)
|
||||
return FALSE;
|
||||
|
||||
@ -444,7 +444,7 @@ each_part (MuMsg *msg, MuMsgPart *part, PartData *pdata)
|
||||
/* now, for non-body parts with some MIME-types, index the
|
||||
* content as well */
|
||||
if (mu_msg_part_looks_like_attachment (part, FALSE))
|
||||
maybe_index_text_part (part, pdata);
|
||||
maybe_index_text_part (msg, part, pdata);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1215,8 +1215,12 @@ cmd_ping (ServerContext *ctx, GSList *args, GError **err)
|
||||
return print_and_clear_g_error (err);
|
||||
|
||||
print_expr ("(:pong \"" PACKAGE_NAME "\" "
|
||||
" :props ("
|
||||
#ifdef BUILD_CRYPTO
|
||||
" :crypto t "
|
||||
#endif /*BUILD_CRYPTO*/
|
||||
" :version \"" VERSION "\" "
|
||||
":doccount %u)", doccount);
|
||||
" :doccount %u))",doccount);
|
||||
|
||||
return MU_OK;
|
||||
}
|
||||
@ -1342,6 +1346,7 @@ cmd_view (ServerContext *ctx, GSList *args, GError **err)
|
||||
unsigned docid;
|
||||
char *sexp;
|
||||
MuMsgOptions opts;
|
||||
gboolean decrypt;
|
||||
|
||||
opts = MU_MSG_OPTION_CHECK_SIGNATURES;
|
||||
if (get_bool_from_args (args, "extract-images", FALSE, err))
|
||||
@ -1351,6 +1356,8 @@ cmd_view (ServerContext *ctx, GSList *args, GError **err)
|
||||
if (get_bool_from_args (args, "auto-retrieve-key", FALSE, NULL))
|
||||
opts |= MU_MSG_OPTION_AUTO_RETRIEVE_KEY;
|
||||
|
||||
decrypt = get_bool_from_args (args, "extract-encrypted", FALSE, err);
|
||||
|
||||
docid = determine_docid (ctx->query, args, err);
|
||||
if (docid == MU_STORE_INVALID_DOCID) {
|
||||
print_and_clear_g_error (err);
|
||||
@ -1363,6 +1370,7 @@ cmd_view (ServerContext *ctx, GSList *args, GError **err)
|
||||
return MU_OK;
|
||||
}
|
||||
|
||||
mu_msg_set_auto_decrypt (msg, decrypt);
|
||||
sexp = mu_msg_to_sexp (msg, docid, NULL, opts);
|
||||
mu_msg_unref (msg);
|
||||
|
||||
|
||||
85
mu/mu-cmd.c
85
mu/mu-cmd.c
@ -111,94 +111,19 @@ print_field (const char* field, const char *val, gboolean color)
|
||||
fputs ("\n", stdout);
|
||||
}
|
||||
|
||||
static char*
|
||||
get_password (const char *user_id, const char *prompt_ctx,
|
||||
gboolean reprompt, gpointer user_data)
|
||||
{
|
||||
char *pass, *prompt;
|
||||
if (reprompt)
|
||||
g_printerr ("Incorrect password. Please try again\n");
|
||||
/* else */
|
||||
/* g_print ("mu: %s\n", prompt_ctx); *\/ */
|
||||
|
||||
prompt = g_strdup_printf ("mu: password for %s: ", user_id);
|
||||
pass = getpass (prompt);
|
||||
g_free (prompt);
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
|
||||
struct _DData {
|
||||
GString *gstr;
|
||||
GError *err;
|
||||
};
|
||||
typedef struct _DData DData;
|
||||
|
||||
static void
|
||||
each_decrypted_part (MuMsgDecryptedPart *dpart, DData *ddata)
|
||||
{
|
||||
gchar *str;
|
||||
|
||||
if (ddata->err)
|
||||
return;
|
||||
|
||||
str = mu_msg_decrypted_part_to_string (dpart,
|
||||
&ddata->err);
|
||||
ddata->gstr = g_string_append (ddata->gstr,
|
||||
str ? str : "");
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
|
||||
static gchar*
|
||||
try_decrypt_body (MuMsg *msg, MuConfig *opts)
|
||||
{
|
||||
DData ddata;
|
||||
GError *err;
|
||||
|
||||
err = NULL;
|
||||
ddata.gstr = g_string_sized_new (mu_msg_get_size(msg));
|
||||
ddata.err = NULL;
|
||||
|
||||
if (!mu_msg_part_decrypt_foreach
|
||||
(msg,(MuMsgPartDecryptForeachFunc)each_decrypted_part,
|
||||
(MuMsgPartPasswordFunc)get_password,
|
||||
&ddata, MU_MSG_OPTION_USE_AGENT, &err))
|
||||
goto errexit;
|
||||
|
||||
if (ddata.err)
|
||||
goto errexit;
|
||||
|
||||
return g_string_free (ddata.gstr, FALSE);
|
||||
|
||||
errexit:
|
||||
g_warning ("decryption failed: %s",
|
||||
err ? err->message : "something went wrong");
|
||||
g_clear_error (&err);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* a summary_len of 0 mean 'don't show summary, show body */
|
||||
static void
|
||||
body_or_summary (MuMsg *msg, MuConfig *opts)
|
||||
{
|
||||
const char *str;
|
||||
const char *body;
|
||||
char *decrypted;
|
||||
gboolean color;
|
||||
|
||||
color = !opts->nocolor;
|
||||
body = mu_msg_get_body_text (msg);
|
||||
|
||||
str = mu_msg_get_body_text (msg);
|
||||
decrypted = NULL;
|
||||
|
||||
if (!str && opts->decrypt)
|
||||
decrypted = try_decrypt_body (msg, opts);
|
||||
if (!str && !decrypted)
|
||||
return; /* no body -- nothing more to do */
|
||||
body = str ? str : decrypted;
|
||||
if (!body)
|
||||
return;
|
||||
|
||||
if (opts->summary_len != 0) {
|
||||
gchar *summ;
|
||||
@ -210,8 +135,6 @@ body_or_summary (MuMsg *msg, MuConfig *opts)
|
||||
mu_util_print_encoded ("\n%s\n", body);
|
||||
color_maybe (MU_COLOR_DEFAULT);
|
||||
}
|
||||
|
||||
g_free (decrypted);
|
||||
}
|
||||
|
||||
|
||||
@ -265,6 +188,8 @@ handle_msg (const char *fname, MuConfig *opts, GError **err)
|
||||
if (!msg)
|
||||
return FALSE;
|
||||
|
||||
mu_msg_set_auto_decrypt (msg, opts->decrypt);
|
||||
|
||||
switch (opts->format) {
|
||||
case MU_CONFIG_FORMAT_PLAIN:
|
||||
rv = view_msg_plain (msg, opts);
|
||||
|
||||
Reference in New Issue
Block a user