mirror of https://github.com/djcb/mu.git
* lib: add support for asking user for password from console
This commit is contained in:
parent
52bc720258
commit
61ade73332
|
@ -327,6 +327,26 @@ static gboolean handle_mime_object (MuMsg *msg,
|
|||
unsigned index, MuMsgPartForeachFunc func,
|
||||
gpointer user_data);
|
||||
|
||||
|
||||
#ifdef BUILD_CRYPTO
|
||||
static gchar*
|
||||
get_console_pw (const char* user_id, const char *prompt_ctx,
|
||||
gboolean reprompt, gpointer user_data)
|
||||
{
|
||||
char *prompt, *pass;
|
||||
|
||||
if (reprompt)
|
||||
g_print ("Authentication failed. Please try again\n");
|
||||
|
||||
prompt = g_strdup_printf ("Password for %s: ", user_id);
|
||||
|
||||
pass = mu_util_read_password (prompt);
|
||||
g_free (prompt);
|
||||
|
||||
return pass;
|
||||
}
|
||||
#endif /*BUILD_CRYPTO*/
|
||||
|
||||
/* call 'func' with information about this MIME-part */
|
||||
static gboolean
|
||||
handle_encrypted_part (MuMsg *msg,
|
||||
|
@ -337,9 +357,16 @@ handle_encrypted_part (MuMsg *msg,
|
|||
#ifdef BUILD_CRYPTO
|
||||
GError *err;
|
||||
GMimeObject *dec;
|
||||
MuMsgPartPasswordFunc pw_func;
|
||||
|
||||
if (opts & MU_MSG_OPTION_CONSOLE_PASSWORD)
|
||||
pw_func = (MuMsgPartPasswordFunc)get_console_pw;
|
||||
else
|
||||
pw_func = NULL;
|
||||
|
||||
|
||||
err = NULL;
|
||||
dec = mu_msg_crypto_decrypt_part (part, opts, NULL, NULL, &err);
|
||||
dec = mu_msg_crypto_decrypt_part (part, opts, pw_func, NULL, &err);
|
||||
if (err) {
|
||||
g_warning ("error decrypting part: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
|
|
|
@ -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
|
||||
|
@ -68,28 +68,13 @@ struct _MuMsg {
|
|||
* convert a GMimePart to a string
|
||||
*
|
||||
* @param part a GMimePart
|
||||
* @param err will receive TRUE if there was an error, FALSE otherwise. Must NOT be NULL.
|
||||
* @param err will receive TRUE if there was an error, FALSE
|
||||
* otherwise. Must NOT be NULL.
|
||||
*
|
||||
* @return utf8 string for this MIME part, to be freed by caller
|
||||
*/
|
||||
gchar* mu_msg_mime_part_to_string (GMimePart *part, gboolean *err);
|
||||
|
||||
|
||||
/* /\** */
|
||||
/* * write a GMimeObject to a file */
|
||||
/* * */
|
||||
/* * @param obj a GMimeObject */
|
||||
/* * @param fullpath full file path */
|
||||
/* * @param overwrite allow overwriting existing file */
|
||||
/* * @param if file already exist, don't bother to write */
|
||||
/* * @param err receives error information */
|
||||
/* * */
|
||||
/* * @return TRUE if writing succeeded, FALSE otherwise. */
|
||||
/* *\/ */
|
||||
/* gboolean mu_msg_part_mime_save_object (GMimeObject *obj, const char *fullpath, */
|
||||
/* gboolean overwrite, gboolean use_existing, */
|
||||
/* GError **err); */
|
||||
|
||||
gchar* mu_msg_mime_part_to_string (GMimePart *part, gboolean *err)
|
||||
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -108,7 +93,6 @@ void mu_mime_message_foreach (GMimeMessage *msg, gboolean decrypt,
|
|||
gpointer user_data);
|
||||
|
||||
#ifdef BUILD_CRYPTO
|
||||
|
||||
/**
|
||||
* callback function to retrieve a password from the user
|
||||
*
|
||||
|
|
|
@ -48,6 +48,9 @@ enum _MuMsgOptions {
|
|||
MU_MSG_OPTION_USE_AGENT = 1 << 6,
|
||||
/* MU_MSG_OPTION_USE_PKCS7 = 1 << 7, /\* gpg is the default *\/ */
|
||||
|
||||
/* get password from console if needed */
|
||||
MU_MSG_OPTION_CONSOLE_PASSWORD = 1 << 7,
|
||||
|
||||
MU_MSG_OPTION_DECRYPT = 1 << 8,
|
||||
|
||||
/* misc */
|
||||
|
|
Loading…
Reference in New Issue