diff --git a/guile/mu-guile-message.c b/guile/mu-guile-message.c index 4ead16b2..24af3411 100644 --- a/guile/mu-guile-message.c +++ b/guile/mu-guile-message.c @@ -358,7 +358,7 @@ SCM_DEFINE (get_parts, "mu:c:get-parts", 1, 1, 0, msgwrap = (MuMsgWrapper*) SCM_CDR(MSG); mu_msg_part_foreach (msgwrap->_msg, (MuMsgPartForeachFunc)each_part, - &attinfo, MU_MSG_PART_OPTION_NONE); + &attinfo, MU_MSG_OPTION_NONE); /* explicitly close the file backend, so we won't run of fds */ mu_msg_unload_msg_file (msgwrap->_msg); diff --git a/lib/mu-msg-crypto.c b/lib/mu-msg-crypto.c index dffa905c..35002e2a 100644 --- a/lib/mu-msg-crypto.c +++ b/lib/mu-msg-crypto.c @@ -43,7 +43,7 @@ dummy_password_requester (GMimeCryptoContext *ctx, const char *user_id, GMimeCryptoContext* -get_gpg_crypto_context (MuMsgPartOptions opts, GError **err) +get_gpg_crypto_context (MuMsgOptions opts, GError **err) { GMimeCryptoContext *ctx; const char *prog; @@ -72,18 +72,18 @@ get_gpg_crypto_context (MuMsgPartOptions opts, GError **err) g_mime_gpg_context_set_use_agent (GMIME_GPG_CONTEXT(ctx), - opts & MU_MSG_PART_OPTION_USE_AGENT); + opts & MU_MSG_OPTION_USE_AGENT); g_mime_gpg_context_set_always_trust (GMIME_GPG_CONTEXT(ctx), FALSE); g_mime_gpg_context_set_auto_key_retrieve (GMIME_GPG_CONTEXT(ctx), - opts & MU_MSG_PART_OPTION_AUTO_RETRIEVE_KEY); + opts & MU_MSG_OPTION_AUTO_RETRIEVE_KEY); return ctx; } GMimeCryptoContext* -get_pkcs7_crypto_context (MuMsgPartOptions opts, GError **err) +get_pkcs7_crypto_context (MuMsgOptions opts, GError **err) { GMimeCryptoContext *ctx; @@ -252,7 +252,7 @@ error_sig_infos (void) GSList* -mu_msg_mime_sig_infos (GMimeMultipartSigned *sigmpart, MuMsgPartOptions opts, +mu_msg_mime_sig_infos (GMimeMultipartSigned *sigmpart, MuMsgOptions opts, GError **err) { int i; @@ -266,7 +266,7 @@ mu_msg_mime_sig_infos (GMimeMultipartSigned *sigmpart, MuMsgPartOptions opts, return NULL; /* error */ } - if (opts & MU_MSG_PART_OPTION_USE_PKCS7) + if (opts & MU_MSG_OPTION_USE_PKCS7) cctx = get_pkcs7_crypto_context (opts, err); else cctx = get_gpg_crypto_context (opts, err); diff --git a/lib/mu-msg-part.c b/lib/mu-msg-part.c index c26c51fe..72d0589f 100644 --- a/lib/mu-msg-part.c +++ b/lib/mu-msg-part.c @@ -1,7 +1,7 @@ /* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/ /* -** Copyright (C) 2008-2011 Dirk-Jan C. Binnema +** Copyright (C) 2008-2012 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify it ** under the terms of the GNU General Public License as published by the @@ -88,7 +88,7 @@ struct _PartData { MuMsgPartForeachFunc _func; gpointer _user_data; GMimePart *_body_part; - MuMsgPartOptions _opts; + MuMsgOptions _opts; }; typedef struct _PartData PartData; @@ -245,7 +245,7 @@ msg_part_free (MuMsgPart *pi) static void check_signature_maybe (GMimeObject *parent, GMimeObject *mobj, MuMsgPart *pi, - MuMsgPartOptions opts) + MuMsgOptions opts) { #ifdef BUILD_CRYPTO @@ -266,7 +266,7 @@ check_signature_maybe (GMimeObject *parent, GMimeObject *mobj, MuMsgPart *pi, else return; /* don't know how to handle other kinds */ if (pkcs7) - opts |= MU_MSG_PART_OPTION_USE_PKCS7; /* gpg is the default */ + opts |= MU_MSG_OPTION_USE_PKCS7; /* gpg is the default */ err = NULL; pi->sig_infos = mu_msg_mime_sig_infos @@ -306,7 +306,7 @@ part_foreach_cb (GMimeObject *parent, GMimeObject *mobj, PartData *pdata) if (!mmsg) return; rv = init_msg_part_from_mime_message_part (mmsg, &pi); - if (rv && (pdata->_opts && MU_MSG_PART_OPTION_RECURSE_RFC822)) + if (rv && (pdata->_opts && MU_MSG_OPTION_RECURSE_RFC822)) /* NOTE: this screws up the counting (pdata->_idx) */ g_mime_message_foreach /* recurse */ (mmsg, (GMimeObjectForeachFunc)part_foreach_cb, @@ -315,7 +315,7 @@ part_foreach_cb (GMimeObject *parent, GMimeObject *mobj, PartData *pdata) rv = FALSE; /* ignore */ /* if we have crypto support, check the signature if there is one */ - if (pdata->_opts & MU_MSG_PART_OPTION_CHECK_SIGNATURES) + if (pdata->_opts & MU_MSG_OPTION_CHECK_SIGNATURES) check_signature_maybe (parent, mobj, &pi, pdata->_opts); if (rv) @@ -327,7 +327,7 @@ part_foreach_cb (GMimeObject *parent, GMimeObject *mobj, PartData *pdata) void mu_msg_part_foreach (MuMsg *msg, MuMsgPartForeachFunc func, gpointer user_data, - MuMsgPartOptions opts) + MuMsgOptions opts) { PartData pdata; GMimeMessage *mime_msg; diff --git a/lib/mu-msg-part.h b/lib/mu-msg-part.h index 8a2adb1b..9a912708 100644 --- a/lib/mu-msg-part.h +++ b/lib/mu-msg-part.h @@ -211,19 +211,6 @@ GSList* mu_msg_part_find_files (MuMsg *msg, const GRegex *pattern); typedef void (*MuMsgPartForeachFunc) (MuMsg*, MuMsgPart*, gpointer); -enum _MuMsgPartOptions { - MU_MSG_PART_OPTION_NONE = 0, - MU_MSG_PART_OPTION_RECURSE_RFC822 = 1 << 0, /* recurse into submessages */ - - /* below options are for checking signatures; only effective - * if mu was built with crypto support */ - MU_MSG_PART_OPTION_CHECK_SIGNATURES = 1 << 1, - MU_MSG_PART_OPTION_AUTO_RETRIEVE_KEY = 1 << 2, - MU_MSG_PART_OPTION_USE_AGENT = 1 << 3, - MU_MSG_PART_OPTION_USE_PKCS7 = 1 << 4 /* gpg is the default */ -}; -typedef enum _MuMsgPartOptions MuMsgPartOptions; - /** * call a function for each of the mime part in a message * @@ -235,7 +222,7 @@ typedef enum _MuMsgPartOptions MuMsgPartOptions; * */ void mu_msg_part_foreach (MuMsg *msg, MuMsgPartForeachFunc func, gpointer user_data, - MuMsgPartOptions opts); + MuMsgOptions opts); G_END_DECLS diff --git a/lib/mu-msg-priv.h b/lib/mu-msg-priv.h index 256e53cf..fc7897fa 100644 --- a/lib/mu-msg-priv.h +++ b/lib/mu-msg-priv.h @@ -99,7 +99,7 @@ GMimePart* mu_msg_mime_get_body_part (GMimeMessage *msg, gboolean want_html); * @return a list of MuMsgPartSig, or NULL */ GSList* mu_msg_mime_sig_infos (GMimeMultipartSigned *sigmpart, - MuMsgPartOptions opts, GError **err); + MuMsgOptions opts, GError **err); #endif /*BUILD_CRYPTO*/ G_END_DECLS diff --git a/lib/mu-msg-sexp.c b/lib/mu-msg-sexp.c index 462b6e55..5977a780 100644 --- a/lib/mu-msg-sexp.c +++ b/lib/mu-msg-sexp.c @@ -280,16 +280,15 @@ each_part (MuMsg *msg, MuMsgPart *part, PartInfo *pinfo) static void -append_sexp_parts (GString *gstr, MuMsg *msg, gboolean want_images) +append_sexp_parts (GString *gstr, MuMsg *msg, MuMsgOptions opts) { PartInfo pinfo; pinfo.parts = NULL; - pinfo.want_images = want_images; + pinfo.want_images = opts & MU_MSG_OPTION_EXTRACT_IMAGES; mu_msg_part_foreach (msg, (MuMsgPartForeachFunc)each_part, - &pinfo, MU_MSG_PART_OPTION_CHECK_SIGNATURES); - + &pinfo, opts); if (pinfo.parts) { g_string_append_printf (gstr, "\t:parts (%s)\n", pinfo.parts); g_free (pinfo.parts); @@ -330,15 +329,18 @@ append_sexp_thread_info (GString *gstr, const MuMsgIterThreadInfo *ti) char* mu_msg_to_sexp (MuMsg *msg, unsigned docid, const MuMsgIterThreadInfo *ti, - gboolean header_only, gboolean extract_images) + MuMsgOptions opts) { GString *gstr; time_t t; g_return_val_if_fail (msg, NULL); - g_return_val_if_fail (!(header_only && extract_images), NULL); + g_return_val_if_fail (!((opts & MU_MSG_OPTION_HEADERS_ONLY) && + (opts & MU_MSG_OPTION_EXTRACT_IMAGES)), + NULL); - gstr = g_string_sized_new (header_only ? 1024 : 8192); + gstr = g_string_sized_new ((opts & MU_MSG_OPTION_HEADERS_ONLY) ? + 1024 : 8192); g_string_append (gstr, "(\n"); if (docid != 0) @@ -367,9 +369,9 @@ mu_msg_to_sexp (MuMsg *msg, unsigned docid, const MuMsgIterThreadInfo *ti, /* 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 (!header_only) { + if (!(opts & MU_MSG_OPTION_HEADERS_ONLY)) { append_sexp_message_file_attr (gstr, msg); - append_sexp_parts (gstr, msg, extract_images); + append_sexp_parts (gstr, msg, opts); } /* note, some of the contacts info comes from the file, soe diff --git a/lib/mu-msg.h b/lib/mu-msg.h index b1844db9..66c22ead 100644 --- a/lib/mu-msg.h +++ b/lib/mu-msg.h @@ -24,6 +24,7 @@ #include #include #include +/* #include */ #include /* for MuError and XapianDocument */ G_BEGIN_DECLS @@ -31,6 +32,27 @@ G_BEGIN_DECLS struct _MuMsg; typedef struct _MuMsg MuMsg; +/* options for various functions */ +enum _MuMsgOptions { + MU_MSG_OPTION_NONE = 0, + MU_MSG_OPTION_RECURSE_RFC822 = 1 << 0, /* recurse into submessages */ + + /* for -> sexp conversion */ + + MU_MSG_OPTION_HEADERS_ONLY = 1 << 1, + MU_MSG_OPTION_EXTRACT_IMAGES = 1 << 2, + + /* below options are for checking signatures; only effective + * if mu was built with crypto support */ + MU_MSG_OPTION_CHECK_SIGNATURES = 1 << 3, + MU_MSG_OPTION_AUTO_RETRIEVE_KEY = 1 << 4, + MU_MSG_OPTION_USE_AGENT = 1 << 5, + MU_MSG_OPTION_USE_PKCS7 = 1 << 6 /* gpg is the default */ +}; +typedef enum _MuMsgOptions MuMsgOptions; + + + /** * create a new MuMsg* instance which parses a message and provides * read access to its properties; call mu_msg_unref when done with it. @@ -403,17 +425,23 @@ struct _MuMsgIterThreadInfo; * @param msg a valid message * @param docid the docid for this message, or 0 * @param ti thread info for the current message, or NULL - * @param headers if TRUE, only include message fields which can be - * obtained from the database (this is much faster if the MuMsg is - * database-backed, so no file needs to be opened) - * @param extract_images if TRUE, extract image attachments as temporary - * files and include links to those in the sexp + * @param opts, bitwise OR'ed; + * - MU_MSG_OPTION_HEADERS_ONLY: only include message fields which can be + * obtained from the database (this is much faster if the MuMsg is + * database-backed, so no file needs to be opened) + * - MU_MSG_OPTION_EXTRACT_IMAGES: extract image attachments as temporary + * files and include links to those in the sexp + * and for message parts: + * MU_MSG_OPTION_CHECK_SIGNATURES: check signatures + * MU_MSG_OPTION_AUTO_RETRIEVE_KEY: attempt to retrieve keys online + * MU_MSG_OPTION_USE_AGENT: attempt to use GPG-agent + * MU_MSG_OPTION_USE_PKCS7: attempt to use PKCS (instead of gpg) * * @return a string with the sexp (free with g_free) or NULL in case of error */ char* mu_msg_to_sexp (MuMsg *msg, unsigned docid, const struct _MuMsgIterThreadInfo *ti, - gboolean headers_only, gboolean extract_images); + MuMsgOptions ops); /** * move a message to another maildir; note that this does _not_ update diff --git a/lib/mu-store-write.cc b/lib/mu-store-write.cc index 30677463..084361b4 100644 --- a/lib/mu-store-write.cc +++ b/lib/mu-store-write.cc @@ -473,7 +473,7 @@ add_terms_values_attach (Xapian::Document& doc, MuMsg *msg, PartData pdata (doc, mfid, strchunk); mu_msg_part_foreach (msg, (MuMsgPartForeachFunc)each_part, &pdata, - MU_MSG_PART_OPTION_RECURSE_RFC822); + MU_MSG_OPTION_RECURSE_RFC822); } diff --git a/mu/mu-cmd-extract.c b/mu/mu-cmd-extract.c index 50b2eaee..de873d9f 100644 --- a/mu/mu-cmd-extract.c +++ b/mu/mu-cmd-extract.c @@ -244,7 +244,7 @@ save_certain_parts (MuMsg *msg, gboolean attachments_only, mu_msg_part_foreach (msg, (MuMsgPartForeachFunc)save_part_if, - &sd, MU_MSG_PART_OPTION_NONE); + &sd, MU_MSG_OPTION_NONE); if (sd.saved_num == 0) { g_warning ("no %s extracted from this message", @@ -347,7 +347,7 @@ show_parts (const char* path, MuConfig *opts, GError **err) mu_msg_part_foreach (msg, (MuMsgPartForeachFunc)each_part_show, GUINT_TO_POINTER(!opts->nocolor), - MU_MSG_PART_OPTION_NONE); + MU_MSG_OPTION_NONE); mu_msg_unref (msg); diff --git a/mu/mu-cmd-find.c b/mu/mu-cmd-find.c index 98e65083..54a81637 100644 --- a/mu/mu-cmd-find.c +++ b/mu/mu-cmd-find.c @@ -493,7 +493,7 @@ output_sexp (MuMsg *msg, MuMsgIter *iter, MuConfig *opts, GError **err) ti = opts->threads ? mu_msg_iter_get_thread_info (iter) : NULL; sexp = mu_msg_to_sexp (msg, mu_msg_iter_get_docid (iter), - ti, TRUE, FALSE); + ti, MU_MSG_OPTION_HEADERS_ONLY); fputs (sexp, stdout); g_free (sexp); diff --git a/mu/mu-cmd-server.c b/mu/mu-cmd-server.c index 6b35d484..53e71dab 100644 --- a/mu/mu-cmd-server.c +++ b/mu/mu-cmd-server.c @@ -453,7 +453,7 @@ include_attachments (MuMsg *msg) attlist = NULL; mu_msg_part_foreach (msg, (MuMsgPartForeachFunc)each_part, - &attlist, MU_MSG_PART_OPTION_NONE); + &attlist, MU_MSG_OPTION_NONE); gstr = g_string_sized_new (512); gstr = g_string_append_c (gstr, '('); @@ -518,7 +518,8 @@ cmd_compose (ServerContext *ctx, GSList *args, GError **err) print_and_clear_g_error (err); return MU_OK; } - sexp = mu_msg_to_sexp (msg, atoi(docidstr), NULL, FALSE, FALSE); + sexp = mu_msg_to_sexp (msg, atoi(docidstr), NULL, + MU_MSG_OPTION_NONE); atts = (ctype == FORWARD) ? include_attachments (msg) : NULL; mu_msg_unref (msg); } else @@ -655,7 +656,7 @@ print_sexps (MuMsgIter *iter, gboolean threads, unsigned maxnum) ti = threads ? mu_msg_iter_get_thread_info (iter) : NULL; sexp = mu_msg_to_sexp (msg, mu_msg_iter_get_docid (iter), - ti, TRUE, FALSE); + ti, MU_MSG_OPTION_HEADERS_ONLY); print_expr ("%s", sexp); g_free (sexp); ++u; @@ -1081,8 +1082,7 @@ do_move (MuStore *store, unsigned docid, MuMsg *msg, const char *maildir, print_and_clear_g_error (err); } - sexp = mu_msg_to_sexp (msg, docid, NULL, FALSE/*include body*/, - FALSE/*do not include images*/); + sexp = mu_msg_to_sexp (msg, docid, NULL, MU_MSG_OPTION_NONE); /* note, the :move t thing is a hint to the frontend that it * could remove the particular header */ print_expr ("(:update %s :move %s)", sexp, @@ -1343,13 +1343,15 @@ cmd_view (ServerContext *ctx, GSList *args, GError **err) MuMsg *msg; unsigned docid; char *sexp; - gboolean extract_images; + MuMsgOptions opts; - extract_images = get_bool_from_args (args, "extract-images", FALSE, err); - if (err && *err) { - print_and_clear_g_error (err); - return MU_OK; - } + opts = MU_MSG_OPTION_CHECK_SIGNATURES; + if (get_bool_from_args (args, "extract-images", FALSE, err)) + opts |= MU_MSG_OPTION_EXTRACT_IMAGES; + if (get_bool_from_args (args, "use-agent", FALSE, NULL)) + opts |= MU_MSG_OPTION_USE_AGENT; + if (get_bool_from_args (args, "auto-retrieve-key", FALSE, NULL)) + opts |= MU_MSG_OPTION_AUTO_RETRIEVE_KEY; docid = determine_docid (ctx->query, args, err); if (docid == MU_STORE_INVALID_DOCID) { @@ -1363,7 +1365,7 @@ cmd_view (ServerContext *ctx, GSList *args, GError **err) return MU_OK; } - sexp = mu_msg_to_sexp (msg, docid, NULL, FALSE, extract_images); + sexp = mu_msg_to_sexp (msg, docid, NULL, opts); mu_msg_unref (msg); print_expr ("(:view %s)\n", sexp); diff --git a/mu/mu-cmd.c b/mu/mu-cmd.c index bb11c78b..c0fed2bc 100644 --- a/mu/mu-cmd.c +++ b/mu/mu-cmd.c @@ -52,7 +52,7 @@ view_msg_sexp (MuMsg *msg) { char *sexp; - sexp = mu_msg_to_sexp (msg, 0, NULL, FALSE, FALSE); + sexp = mu_msg_to_sexp (msg, 0, NULL, MU_MSG_OPTION_NONE); fputs (sexp, stdout); g_free (sexp); @@ -84,7 +84,7 @@ get_attach_str (MuMsg *msg) attach = NULL; mu_msg_part_foreach (msg, (MuMsgPartForeachFunc)each_part, &attach, - MU_MSG_PART_OPTION_NONE); + MU_MSG_OPTION_NONE); return attach; } @@ -437,7 +437,7 @@ MuError mu_cmd_verify (MuConfig *opts, GError **err) { MuMsg *msg; - MuMsgPartOptions partopts; + MuMsgOptions msgopts; VData vdata; g_return_val_if_fail (opts, MU_ERROR_INTERNAL); @@ -448,18 +448,18 @@ mu_cmd_verify (MuConfig *opts, GError **err) if (!msg) return MU_ERROR; - partopts = MU_MSG_PART_OPTION_CHECK_SIGNATURES; + msgopts = MU_MSG_OPTION_CHECK_SIGNATURES; if (opts->auto_retrieve) - partopts |= MU_MSG_PART_OPTION_AUTO_RETRIEVE_KEY; + msgopts |= MU_MSG_OPTION_AUTO_RETRIEVE_KEY; if (opts->use_agent) - partopts |= MU_MSG_PART_OPTION_USE_AGENT; + msgopts |= MU_MSG_OPTION_USE_AGENT; vdata.status = MU_MSG_PART_SIG_STATUS_UNKNOWN; vdata.opts = opts; vdata.msg = NULL; mu_msg_part_foreach (msg,(MuMsgPartForeachFunc)each_sig, &vdata, - partopts); + msgopts); /* if there's anything bad, all goodness goes away */ if (vdata.status & MU_MSG_PART_SIG_STATUS_BAD || diff --git a/widgets/mu-msg-attach-view.c b/widgets/mu-msg-attach-view.c index 6020dec0..4dd7956c 100644 --- a/widgets/mu-msg-attach-view.c +++ b/widgets/mu-msg-attach-view.c @@ -288,7 +288,7 @@ mu_msg_attach_view_set_message (MuMsgAttachView *self, MuMsg *msg) cbdata.store = store; cbdata.count = 0; mu_msg_part_foreach (msg, (MuMsgPartForeachFunc)each_part, &cbdata, - MU_MSG_PART_OPTION_NONE); + MU_MSG_OPTION_NONE); return cbdata.count; }