mu: some cosmetics / minor cleanup

This commit is contained in:
djcb 2016-10-25 20:34:08 +03:00
parent 03dd1d653b
commit 7526f118ba
4 changed files with 66 additions and 74 deletions

View File

@ -592,9 +592,10 @@ clear_links (const gchar* dirname, DIR *dir, GError **err)
errno = 0; errno = 0;
while ((entry = readdir (dir))) { while ((entry = readdir (dir))) {
const char *fp; const char *fp;
char *fullpath; char *fullpath;
unsigned char d_type; unsigned char d_type;
guint len;
/* ignore empty, dot thingies */ /* ignore empty, dot thingies */
if (entry->d_name[0] == '\0' || entry->d_name[0] == '.') if (entry->d_name[0] == '\0' || entry->d_name[0] == '.')
@ -603,9 +604,10 @@ clear_links (const gchar* dirname, DIR *dir, GError **err)
/* we have to copy the buffer from fullpath_s, because /* we have to copy the buffer from fullpath_s, because
* it returns a static buffer and we are * it returns a static buffer and we are
* recursive*/ * recursive*/
fp = mu_str_fullpath_s (dirname, entry->d_name); fp = mu_str_fullpath_s (dirname, entry->d_name);
fullpath = g_newa (char, strlen(fp) + 1); len = strlen(fp);
strcpy (fullpath, fp); fullpath = g_newa (char, len + 1);
strncpy (fullpath, fp, len);
d_type = GET_DTYPE (entry, fullpath); d_type = GET_DTYPE (entry, fullpath);
@ -767,18 +769,11 @@ mu_maildir_get_maildir_from_path (const char* path)
static char* static char*
get_new_basename (void) get_new_basename (void)
{ {
char hostname[64];
if (gethostname (hostname, sizeof(hostname)) == -1)
memcpy (hostname, "localhost", sizeof(hostname));
else
hostname[sizeof(hostname)-1] = '\0';
return g_strdup_printf ("%u.%08x%08x.%s", return g_strdup_printf ("%u.%08x%08x.%s",
(guint)time(NULL), (guint)time(NULL),
g_random_int(), g_random_int(),
(gint32)g_get_monotonic_time (), (gint32)g_get_monotonic_time (),
hostname); g_get_host_name ());
} }

View File

@ -155,8 +155,8 @@ accumulate_text (MuMsg *msg, MuMsgPart *part, GString **gstrp)
/* declaration, so we can use it earlier */ /* declaration, so we can use it earlier */
static gboolean static gboolean
handle_mime_object (MuMsg *msg, GMimeObject *mobj, GMimeObject *parent, handle_mime_object (MuMsg *msg, GMimeObject *mobj, GMimeObject *parent,
MuMsgOptions opts, unsigned *index, gboolean decrypted, MuMsgOptions opts, unsigned *index, gboolean decrypted,
MuMsgPartForeachFunc func, gpointer user_data); MuMsgPartForeachFunc func, gpointer user_data);
static char* static char*
get_text_from_mime_msg (MuMsg *msg, GMimeMessage *mmsg, MuMsgOptions opts) get_text_from_mime_msg (MuMsg *msg, GMimeMessage *mmsg, MuMsgOptions opts)
@ -167,11 +167,11 @@ get_text_from_mime_msg (MuMsg *msg, GMimeMessage *mmsg, MuMsgOptions opts)
index = 1; index = 1;
gstr = g_string_sized_new (4096); gstr = g_string_sized_new (4096);
handle_mime_object (msg, handle_mime_object (msg,
mmsg->mime_part, mmsg->mime_part,
(GMimeObject *) mmsg, (GMimeObject *) mmsg,
opts, opts,
&index, &index,
FALSE, FALSE,
(MuMsgPartForeachFunc)accumulate_text, (MuMsgPartForeachFunc)accumulate_text,
&gstr); &gstr);
@ -432,7 +432,7 @@ handle_encrypted_part (MuMsg *msg, GMimeMultipartEncrypted *part,
if (dec) { if (dec) {
rv = handle_mime_object (msg, dec, (GMimeObject *) part, rv = handle_mime_object (msg, dec, (GMimeObject *) part,
opts, index, TRUE, func, user_data); opts, index, TRUE, func, user_data);
g_object_unref (dec); g_object_unref (dec);
} else { } else {
/* On failure to decrypt, list the encrypted part as /* On failure to decrypt, list the encrypted part as
@ -446,7 +446,7 @@ handle_encrypted_part (MuMsg *msg, GMimeMultipartEncrypted *part,
g_return_val_if_fail (GMIME_IS_PART(encrypted), FALSE); g_return_val_if_fail (GMIME_IS_PART(encrypted), FALSE);
rv = handle_mime_object (msg, encrypted, (GMimeObject *) part, rv = handle_mime_object (msg, encrypted, (GMimeObject *) part,
opts, index, FALSE, func, user_data); opts, index, FALSE, func, user_data);
} }
return rv; return rv;
@ -471,7 +471,7 @@ handle_part (MuMsg *msg, GMimePart *part, GMimeObject *parent,
if (decrypted) if (decrypted)
msgpart.part_type |= MU_MSG_PART_TYPE_DECRYPTED; msgpart.part_type |= MU_MSG_PART_TYPE_DECRYPTED;
else if ((opts & MU_MSG_OPTION_DECRYPT) && else if ((opts & MU_MSG_OPTION_DECRYPT) &&
GMIME_IS_MULTIPART_ENCRYPTED (parent)) GMIME_IS_MULTIPART_ENCRYPTED (parent))
msgpart.part_type |= MU_MSG_PART_TYPE_ENCRYPTED; msgpart.part_type |= MU_MSG_PART_TYPE_ENCRYPTED;
@ -539,13 +539,13 @@ handle_message_part (MuMsg *msg, GMimeMessagePart *mimemsgpart,
mmsg = g_mime_message_part_get_message (mimemsgpart); mmsg = g_mime_message_part_get_message (mimemsgpart);
if (mmsg) if (mmsg)
return handle_mime_object (msg, return handle_mime_object (msg,
mmsg->mime_part, mmsg->mime_part,
parent, parent,
opts, opts,
index, index,
decrypted, decrypted,
func, func,
user_data); user_data);
} }
return TRUE; return TRUE;
@ -553,7 +553,7 @@ handle_message_part (MuMsg *msg, GMimeMessagePart *mimemsgpart,
static gboolean static gboolean
handle_multipart (MuMsg *msg, GMimeMultipart *mpart, GMimeObject *parent, handle_multipart (MuMsg *msg, GMimeMultipart *mpart, GMimeObject *parent,
MuMsgOptions opts, unsigned *index, gboolean decrypted, MuMsgOptions opts, unsigned *index, gboolean decrypted,
MuMsgPartForeachFunc func, gpointer user_data) MuMsgPartForeachFunc func, gpointer user_data)
{ {
gboolean res; gboolean res;
@ -564,8 +564,8 @@ handle_multipart (MuMsg *msg, GMimeMultipart *mpart, GMimeObject *parent,
for (i = 0; i < mpart->children->len; i++) { for (i = 0; i < mpart->children->len; i++) {
part = (GMimeObject *) mpart->children->pdata[i]; part = (GMimeObject *) mpart->children->pdata[i];
res &= handle_mime_object (msg, part, parent, res &= handle_mime_object (msg, part, parent,
opts, index, decrypted, opts, index, decrypted,
func, user_data); func, user_data);
} }
return res; return res;
@ -586,14 +586,14 @@ handle_mime_object (MuMsg *msg, GMimeObject *mobj, GMimeObject *parent,
(msg, GMIME_MESSAGE_PART(mobj), (msg, GMIME_MESSAGE_PART(mobj),
parent, opts, index, decrypted, func, user_data); parent, opts, index, decrypted, func, user_data);
else if ((opts & MU_MSG_OPTION_VERIFY) && else if ((opts & MU_MSG_OPTION_VERIFY) &&
GMIME_IS_MULTIPART_SIGNED (mobj)) { GMIME_IS_MULTIPART_SIGNED (mobj)) {
check_signature check_signature
(msg, GMIME_MULTIPART_SIGNED (mobj), opts); (msg, GMIME_MULTIPART_SIGNED (mobj), opts);
return handle_multipart return handle_multipart
(msg, GMIME_MULTIPART (mobj), mobj, opts, (msg, GMIME_MULTIPART (mobj), mobj, opts,
index, decrypted, func, user_data); index, decrypted, func, user_data);
} else if ((opts & MU_MSG_OPTION_DECRYPT) && } else if ((opts & MU_MSG_OPTION_DECRYPT) &&
GMIME_IS_MULTIPART_ENCRYPTED (mobj)) GMIME_IS_MULTIPART_ENCRYPTED (mobj))
return handle_encrypted_part return handle_encrypted_part
(msg, GMIME_MULTIPART_ENCRYPTED (mobj), (msg, GMIME_MULTIPART_ENCRYPTED (mobj),
opts, index, func, user_data); opts, index, func, user_data);
@ -618,13 +618,13 @@ mu_msg_part_foreach (MuMsg *msg, MuMsgOptions opts,
return FALSE; return FALSE;
return handle_mime_object (msg, return handle_mime_object (msg,
msg->_file->_mime_msg->mime_part, msg->_file->_mime_msg->mime_part,
(GMimeObject *) msg->_file->_mime_msg, (GMimeObject *) msg->_file->_mime_msg,
opts, opts,
&index, &index,
FALSE, FALSE,
func, func,
user_data); user_data);
} }
@ -785,7 +785,7 @@ mu_msg_part_get_cache_path (MuMsg *msg, MuMsgOptions opts, guint partid,
/* g_compute_checksum_for_string may be better, but requires /* g_compute_checksum_for_string may be better, but requires
* rel. new glib (2.16) */ * rel. new glib (2.16) */
dirname = g_strdup_printf ("%s%c%x%c%u", dirname = g_strdup_printf ("%s%c%x%c%u",
mu_util_cache_dir(), G_DIR_SEPARATOR, mu_util_cache_dir(), G_DIR_SEPARATOR,
g_str_hash (path), G_DIR_SEPARATOR, g_str_hash (path), G_DIR_SEPARATOR,
partid); partid);
@ -813,7 +813,7 @@ mu_msg_part_save (MuMsg *msg, MuMsgOptions opts,
g_return_val_if_fail (msg, FALSE); g_return_val_if_fail (msg, FALSE);
g_return_val_if_fail (fullpath, FALSE); g_return_val_if_fail (fullpath, FALSE);
g_return_val_if_fail (!((opts & MU_MSG_OPTION_OVERWRITE) && g_return_val_if_fail (!((opts & MU_MSG_OPTION_OVERWRITE) &&
(opts & MU_MSG_OPTION_USE_EXISTING)), FALSE); (opts & MU_MSG_OPTION_USE_EXISTING)), FALSE);
if (!mu_msg_load_msg_file (msg, err)) if (!mu_msg_load_msg_file (msg, err))
return FALSE; return FALSE;
@ -888,7 +888,7 @@ mu_msg_find_index_for_cid (MuMsg *msg, MuMsgOptions opts,
return get_matching_part_index (msg, opts, return get_matching_part_index (msg, opts,
(MuMsgPartMatchFunc)match_cid, (MuMsgPartMatchFunc)match_cid,
(gpointer)(char*)cid); (gpointer)cid);
} }
struct _RxMatchData { struct _RxMatchData {

View File

@ -123,7 +123,7 @@ mu_util_create_tmpdir (void)
{ {
gchar *dirname; gchar *dirname;
dirname = g_strdup_printf ("%s%cmu-%d%c%x", dirname = g_strdup_printf ("%s%cmu-%d%c%x",
g_get_tmp_dir(), g_get_tmp_dir(),
G_DIR_SEPARATOR, G_DIR_SEPARATOR,
getuid(), getuid(),
@ -193,45 +193,45 @@ mu_util_check_dir (const gchar* path, gboolean readable, gboolean writeable)
gchar* gchar*
mu_util_guess_maildir (void) mu_util_guess_maildir (void)
{ {
const gchar *mdir1, *home; const gchar *mdir1, *home;
/* first, try MAILDIR */ /* first, try MAILDIR */
mdir1 = g_getenv ("MAILDIR"); mdir1 = g_getenv ("MAILDIR");
if (mdir1 && mu_util_check_dir (mdir1, TRUE, FALSE)) if (mdir1 && mu_util_check_dir (mdir1, TRUE, FALSE))
return g_strdup (mdir1); return g_strdup (mdir1);
/* then, try <home>/Maildir */ /* then, try <home>/Maildir */
home = g_get_home_dir(); home = g_get_home_dir();
if (home) { if (home) {
char *mdir2; char *mdir2;
mdir2 = g_strdup_printf ("%s%cMaildir", mdir2 = g_strdup_printf ("%s%cMaildir",
home, G_DIR_SEPARATOR); home, G_DIR_SEPARATOR);
if (mu_util_check_dir (mdir2, TRUE, FALSE)) if (mu_util_check_dir (mdir2, TRUE, FALSE))
return mdir2; return mdir2;
g_free (mdir2); g_free (mdir2);
} }
/* nope; nothing found */ /* nope; nothing found */
return NULL; return NULL;
} }
gchar* gchar*
mu_util_guess_mu_homedir (void) mu_util_guess_mu_homedir (void)
{ {
const char* home; const char* home;
/* g_get_home_dir use /etc/passwd, not $HOME; this is better, /* g_get_home_dir use /etc/passwd, not $HOME; this is better,
* as HOME may be wrong when using 'sudo' etc.*/ * as HOME may be wrong when using 'sudo' etc.*/
home = g_get_home_dir (); home = g_get_home_dir ();
if (!home) { if (!home) {
MU_WRITE_LOG ("failed to determine homedir"); MU_WRITE_LOG ("failed to determine homedir");
return NULL; return NULL;
} }
return g_strdup_printf ("%s%c%s", home ? home : ".", return g_strdup_printf ("%s%c%s", home ? home : ".",
G_DIR_SEPARATOR, ".mu"); G_DIR_SEPARATOR, ".mu");
} }
@ -437,7 +437,6 @@ mu_util_fputs_encoded (const char *str, FILE *stream)
unsigned bytes; unsigned bytes;
char *conv; char *conv;
g_return_val_if_fail (str, FALSE);
g_return_val_if_fail (stream, FALSE); g_return_val_if_fail (stream, FALSE);
/* g_get_charset return TRUE when the locale is UTF8 */ /* g_get_charset return TRUE when the locale is UTF8 */
@ -557,5 +556,3 @@ mu_util_read_password (const char *prompt)
return g_strdup (pass); return g_strdup (pass);
} }

View File

@ -459,7 +459,7 @@ output_plain_fields (MuMsg *msg, const char *fields,
int nonempty; int nonempty;
g_return_if_fail (fields); g_return_if_fail (fields);
for (myfields = fields, nonempty = 0; *myfields; ++myfields) { for (myfields = fields, nonempty = 0; *myfields; ++myfields) {
MuMsgFieldId mfid; MuMsgFieldId mfid;