* refactor: MU_MSG_PART_OPTION -> MU_MSG_OPTION and related changes

This commit is contained in:
djcb
2012-07-18 16:22:10 +03:00
parent b36d684b81
commit acfabfdf4b
13 changed files with 87 additions and 68 deletions

View File

@ -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);

View File

@ -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 <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** 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;

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -24,6 +24,7 @@
#include <mu-flags.h>
#include <mu-msg-fields.h>
#include <mu-msg-prio.h>
/* #include <mu-msg-part.h> */
#include <mu-util.h> /* 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

View File

@ -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);
}