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;
while ((entry = readdir (dir))) {
const char *fp;
char *fullpath;
unsigned char d_type;
const char *fp;
char *fullpath;
unsigned char d_type;
guint len;
/* ignore empty, dot thingies */
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
* it returns a static buffer and we are
* recursive*/
fp = mu_str_fullpath_s (dirname, entry->d_name);
fullpath = g_newa (char, strlen(fp) + 1);
strcpy (fullpath, fp);
fp = mu_str_fullpath_s (dirname, entry->d_name);
len = strlen(fp);
fullpath = g_newa (char, len + 1);
strncpy (fullpath, fp, len);
d_type = GET_DTYPE (entry, fullpath);
@ -767,18 +769,11 @@ mu_maildir_get_maildir_from_path (const char* path)
static char*
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",
(guint)time(NULL),
g_random_int(),
(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 */
static gboolean
handle_mime_object (MuMsg *msg, GMimeObject *mobj, GMimeObject *parent,
MuMsgOptions opts, unsigned *index, gboolean decrypted,
MuMsgPartForeachFunc func, gpointer user_data);
MuMsgOptions opts, unsigned *index, gboolean decrypted,
MuMsgPartForeachFunc func, gpointer user_data);
static char*
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;
gstr = g_string_sized_new (4096);
handle_mime_object (msg,
mmsg->mime_part,
mmsg->mime_part,
(GMimeObject *) mmsg,
opts,
&index,
FALSE,
FALSE,
(MuMsgPartForeachFunc)accumulate_text,
&gstr);
@ -432,7 +432,7 @@ handle_encrypted_part (MuMsg *msg, GMimeMultipartEncrypted *part,
if (dec) {
rv = handle_mime_object (msg, dec, (GMimeObject *) part,
opts, index, TRUE, func, user_data);
opts, index, TRUE, func, user_data);
g_object_unref (dec);
} else {
/* 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);
rv = handle_mime_object (msg, encrypted, (GMimeObject *) part,
opts, index, FALSE, func, user_data);
opts, index, FALSE, func, user_data);
}
return rv;
@ -471,7 +471,7 @@ handle_part (MuMsg *msg, GMimePart *part, GMimeObject *parent,
if (decrypted)
msgpart.part_type |= MU_MSG_PART_TYPE_DECRYPTED;
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;
@ -539,13 +539,13 @@ handle_message_part (MuMsg *msg, GMimeMessagePart *mimemsgpart,
mmsg = g_mime_message_part_get_message (mimemsgpart);
if (mmsg)
return handle_mime_object (msg,
mmsg->mime_part,
parent,
opts,
index,
decrypted,
func,
user_data);
mmsg->mime_part,
parent,
opts,
index,
decrypted,
func,
user_data);
}
return TRUE;
@ -553,7 +553,7 @@ handle_message_part (MuMsg *msg, GMimeMessagePart *mimemsgpart,
static gboolean
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)
{
gboolean res;
@ -564,8 +564,8 @@ handle_multipart (MuMsg *msg, GMimeMultipart *mpart, GMimeObject *parent,
for (i = 0; i < mpart->children->len; i++) {
part = (GMimeObject *) mpart->children->pdata[i];
res &= handle_mime_object (msg, part, parent,
opts, index, decrypted,
func, user_data);
opts, index, decrypted,
func, user_data);
}
return res;
@ -586,14 +586,14 @@ handle_mime_object (MuMsg *msg, GMimeObject *mobj, GMimeObject *parent,
(msg, GMIME_MESSAGE_PART(mobj),
parent, opts, index, decrypted, func, user_data);
else if ((opts & MU_MSG_OPTION_VERIFY) &&
GMIME_IS_MULTIPART_SIGNED (mobj)) {
GMIME_IS_MULTIPART_SIGNED (mobj)) {
check_signature
(msg, GMIME_MULTIPART_SIGNED (mobj), opts);
return handle_multipart
(msg, GMIME_MULTIPART (mobj), mobj, opts,
index, decrypted, func, user_data);
} else if ((opts & MU_MSG_OPTION_DECRYPT) &&
GMIME_IS_MULTIPART_ENCRYPTED (mobj))
GMIME_IS_MULTIPART_ENCRYPTED (mobj))
return handle_encrypted_part
(msg, GMIME_MULTIPART_ENCRYPTED (mobj),
opts, index, func, user_data);
@ -618,13 +618,13 @@ mu_msg_part_foreach (MuMsg *msg, MuMsgOptions opts,
return FALSE;
return handle_mime_object (msg,
msg->_file->_mime_msg->mime_part,
(GMimeObject *) msg->_file->_mime_msg,
opts,
&index,
FALSE,
func,
user_data);
msg->_file->_mime_msg->mime_part,
(GMimeObject *) msg->_file->_mime_msg,
opts,
&index,
FALSE,
func,
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
* 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,
g_str_hash (path), G_DIR_SEPARATOR,
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 (fullpath, FALSE);
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))
return FALSE;
@ -888,7 +888,7 @@ mu_msg_find_index_for_cid (MuMsg *msg, MuMsgOptions opts,
return get_matching_part_index (msg, opts,
(MuMsgPartMatchFunc)match_cid,
(gpointer)(char*)cid);
(gpointer)cid);
}
struct _RxMatchData {

View File

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

View File

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