mirror of
https://github.com/djcb/mu.git
synced 2024-06-20 06:46:50 +02:00
* mu-cmd-find.c, mu-msg-sexp.c, mu-msg.c: refactor for 'make line33' check
This commit is contained in:
parent
5ff92a2e4c
commit
f6a4b7a480
|
@ -455,8 +455,7 @@ output_links (MuMsgIter *iter, const char* linksdir,
|
|||
if (!create_linksdir_maybe (linksdir, clearlinks))
|
||||
return FALSE;
|
||||
|
||||
for (myiter = iter, errseen = FALSE, mycount = 0;
|
||||
!mu_msg_iter_is_done (myiter);
|
||||
for (myiter = iter, errseen = FALSE, mycount = 0; !mu_msg_iter_is_done (myiter);
|
||||
mu_msg_iter_next (myiter)) {
|
||||
|
||||
MuMsg *msg;
|
||||
|
@ -477,8 +476,7 @@ output_links (MuMsgIter *iter, const char* linksdir,
|
|||
}
|
||||
|
||||
if (errseen)
|
||||
g_warning ("error linking some of the messages; maybe the "
|
||||
"database needs to be updated");
|
||||
g_warning ("error linking some of the messages");
|
||||
|
||||
if (count)
|
||||
*count = mycount;
|
||||
|
@ -754,6 +752,25 @@ output_sexp (MuMsgIter *iter, gboolean include_unreadable, size_t *count)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
output_xml_msg (MuMsg *msg)
|
||||
{
|
||||
g_print ("\t<message>\n");
|
||||
print_attr_xml ("from", mu_msg_get_from (msg));
|
||||
print_attr_xml ("to", mu_msg_get_to (msg));
|
||||
print_attr_xml ("cc", mu_msg_get_cc (msg));
|
||||
print_attr_xml ("subject", mu_msg_get_subject (msg));
|
||||
g_print ("\t\t<date>%u</date>\n",
|
||||
(unsigned)mu_msg_get_date (msg));
|
||||
g_print ("\t\t<size>%u</size>\n", mu_msg_get_size (msg));
|
||||
print_attr_xml ("msgid", mu_msg_get_msgid (msg));
|
||||
print_attr_xml ("path", mu_msg_get_path (msg));
|
||||
print_attr_xml ("maildir", mu_msg_get_maildir (msg));
|
||||
g_print ("\t</message>\n");
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
output_xml (MuMsgIter *iter, gboolean include_unreadable, size_t *count)
|
||||
{
|
||||
|
@ -768,8 +785,7 @@ output_xml (MuMsgIter *iter, gboolean include_unreadable, size_t *count)
|
|||
for (myiter = iter, mycount = 0; !mu_msg_iter_is_done (myiter);
|
||||
mu_msg_iter_next (myiter)) {
|
||||
|
||||
MuMsg *msg;
|
||||
|
||||
MuMsg *msg;
|
||||
msg = mu_msg_iter_get_msg (iter, NULL); /* don't unref */
|
||||
if (!msg)
|
||||
return FALSE;
|
||||
|
@ -778,24 +794,11 @@ output_xml (MuMsgIter *iter, gboolean include_unreadable, size_t *count)
|
|||
* readable (ie, live also outside the database) */
|
||||
if (!include_unreadable && !mu_msg_is_readable (msg))
|
||||
continue;
|
||||
|
||||
g_print ("\t<message>\n");
|
||||
print_attr_xml ("from", mu_msg_get_from (msg));
|
||||
print_attr_xml ("to", mu_msg_get_to (msg));
|
||||
print_attr_xml ("cc", mu_msg_get_cc (msg));
|
||||
print_attr_xml ("subject", mu_msg_get_subject (msg));
|
||||
g_print ("\t\t<date>%u</date>\n",
|
||||
(unsigned) mu_msg_get_date (msg));
|
||||
g_print ("\t\t<size>%u</size>\n",
|
||||
(unsigned) mu_msg_get_size (msg));
|
||||
print_attr_xml ("msgid", mu_msg_get_msgid (msg));
|
||||
print_attr_xml ("path", mu_msg_get_path (msg));
|
||||
print_attr_xml ("maildir", mu_msg_get_maildir (msg));
|
||||
g_print ("\t</message>\n");
|
||||
|
||||
output_xml_msg (msg);
|
||||
|
||||
++mycount;
|
||||
}
|
||||
|
||||
g_print ("</messages>\n");
|
||||
|
||||
if (count)
|
||||
|
|
|
@ -91,45 +91,38 @@ static gboolean
|
|||
each_contact (MuMsgContact *c, ContactData *cdata)
|
||||
{
|
||||
char *pair;
|
||||
|
||||
pair = get_name_addr_pair (c);
|
||||
|
||||
|
||||
if (mu_msg_contact_type (c) == MU_MSG_CONTACT_TYPE_FROM) {
|
||||
if (!cdata->from)
|
||||
g_string_append (cdata->gstr, "\t:from (");
|
||||
g_string_append (cdata->gstr, pair);
|
||||
cdata->from = TRUE;
|
||||
}
|
||||
|
||||
if (mu_msg_contact_type (c) == MU_MSG_CONTACT_TYPE_TO) {
|
||||
|
||||
} else if (mu_msg_contact_type (c) == MU_MSG_CONTACT_TYPE_TO) {
|
||||
if (!cdata->to)
|
||||
g_string_append_printf (cdata->gstr,"%s\t:to (",
|
||||
cdata->from ? ")\n" : "");
|
||||
g_string_append (cdata->gstr, pair);
|
||||
g_string_append_printf (cdata->gstr,"%s\t:to (",
|
||||
cdata->from ? ")\n" : "");
|
||||
cdata->to = TRUE;
|
||||
}
|
||||
|
||||
if (mu_msg_contact_type (c) == MU_MSG_CONTACT_TYPE_CC) {
|
||||
|
||||
} else if (mu_msg_contact_type (c) == MU_MSG_CONTACT_TYPE_CC) {
|
||||
if (!cdata->cc)
|
||||
g_string_append_printf (cdata->gstr,"%s\t:cc (",
|
||||
cdata->from||cdata->to ?
|
||||
")\n" : "");
|
||||
g_string_append (cdata->gstr, pair);
|
||||
cdata->cc = TRUE;
|
||||
}
|
||||
|
||||
if (mu_msg_contact_type (c) == MU_MSG_CONTACT_TYPE_BCC) {
|
||||
} else if (mu_msg_contact_type (c) == MU_MSG_CONTACT_TYPE_BCC) {
|
||||
if (!cdata->bcc)
|
||||
g_string_append_printf
|
||||
(cdata->gstr, "%s\t:bcc (",
|
||||
cdata->from||cdata->to||cdata->cc ?
|
||||
")\n" : "");
|
||||
g_string_append (cdata->gstr, pair);
|
||||
cdata->from||cdata->to||cdata->cc ? ")\n":"");
|
||||
cdata->bcc = TRUE;
|
||||
}
|
||||
} else
|
||||
g_return_val_if_reached (FALSE);
|
||||
|
||||
pair = get_name_addr_pair (c);
|
||||
g_string_append (cdata->gstr, pair);
|
||||
g_free (pair);
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -219,6 +212,23 @@ append_sexp_attachments (GString *gstr, MuMsg *msg)
|
|||
}
|
||||
|
||||
|
||||
static void
|
||||
append_sexp_message_file_attr (GString *gstr, MuMsg *msg)
|
||||
{
|
||||
append_sexp_attachments (gstr, msg);
|
||||
|
||||
append_sexp_attr (gstr, "reply-to",
|
||||
mu_msg_get_header (msg, "Reply-To"));
|
||||
append_sexp_attr_list (gstr, "references", mu_msg_get_references (msg));
|
||||
append_sexp_attr (gstr, "in-reply-to",
|
||||
mu_msg_get_header (msg, "In-Reply-To"));
|
||||
|
||||
append_sexp_attr (gstr, "body-txt",
|
||||
mu_msg_get_body_text(msg));
|
||||
append_sexp_attr (gstr, "body-html",
|
||||
mu_msg_get_body_html(msg));
|
||||
}
|
||||
|
||||
char*
|
||||
mu_msg_to_sexp (MuMsg *msg, gboolean dbonly)
|
||||
{
|
||||
|
@ -233,13 +243,12 @@ mu_msg_to_sexp (MuMsg *msg, gboolean dbonly)
|
|||
"subject", mu_msg_get_subject (msg));
|
||||
|
||||
t = mu_msg_get_date (msg);
|
||||
g_string_append_printf (gstr,
|
||||
/* weird time format for emacs 29-bit ints...*/
|
||||
g_string_append_printf (gstr,
|
||||
"\t:date (%u %u 0)\n", (unsigned)(t >> 16),
|
||||
(unsigned)(t & 0xffff));
|
||||
g_string_append_printf (gstr, "\t:size %u\n",
|
||||
(unsigned) mu_msg_get_size (msg));
|
||||
|
||||
|
||||
append_sexp_attr (gstr, "message-id", mu_msg_get_msgid (msg));
|
||||
append_sexp_attr (gstr, "path", mu_msg_get_path (msg));
|
||||
append_sexp_attr (gstr, "maildir", mu_msg_get_maildir (msg));
|
||||
|
@ -249,20 +258,10 @@ mu_msg_to_sexp (MuMsg *msg, gboolean dbonly)
|
|||
|
||||
append_sexp_flags (gstr, msg);
|
||||
|
||||
if (!dbonly) {
|
||||
append_sexp_attachments (gstr, msg);
|
||||
|
||||
append_sexp_attr (gstr, "reply-to",
|
||||
mu_msg_get_header (msg, "Reply-To"));
|
||||
append_sexp_attr_list (gstr, "references", mu_msg_get_references (msg));
|
||||
append_sexp_attr (gstr, "in-reply-to",
|
||||
mu_msg_get_header (msg, "In-Reply-To"));
|
||||
|
||||
append_sexp_attr (gstr, "body-txt",
|
||||
mu_msg_get_body_text(msg));
|
||||
append_sexp_attr (gstr, "body-html",
|
||||
mu_msg_get_body_html(msg));
|
||||
}
|
||||
/* file attr things can only be gotten from the file (ie., mu
|
||||
* view), not from the database (mu find) */
|
||||
if (!dbonly)
|
||||
append_sexp_message_file_attr (gstr, msg);
|
||||
|
||||
g_string_append (gstr, ")\n;;eom\n");
|
||||
|
||||
|
|
72
src/mu-msg.c
72
src/mu-msg.c
|
@ -680,10 +680,6 @@ mu_msg_is_readable (MuMsg *self)
|
|||
== 0) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
enum _MaildirType {
|
||||
MAILDIR_TYPE_CUR,
|
||||
MAILDIR_TYPE_NEW,
|
||||
|
@ -796,6 +792,44 @@ msg_move (const char* oldpath, const char *newfullpath, GError **err)
|
|||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
check_source_file (const char *src, MaildirType *mtype, GError **err)
|
||||
{
|
||||
if (!g_path_is_absolute(src)) {
|
||||
g_set_error (err, 0, MU_ERROR_FILE,
|
||||
"source is not an absolute path: '%s'", src);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*mtype = get_maildir_type (src);
|
||||
if (mtype != MAILDIR_TYPE_CUR && *mtype != MAILDIR_TYPE_NEW) {
|
||||
g_set_error (err, 0, MU_ERROR_FILE,
|
||||
"source is not in a maildir: '%s'", src);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
check_target_dir (const char* targetmdir, GError **err)
|
||||
{
|
||||
if (!g_path_is_absolute(targetmdir)) {
|
||||
g_set_error (err, 0, MU_ERROR_FILE,
|
||||
"target is not an absolute path: '%s'", targetmdir);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!mu_util_check_dir (targetmdir, TRUE, TRUE)) {
|
||||
g_set_error (err, 0, MU_ERROR_FILE,
|
||||
"target is not a read-writable dir: '%s'", targetmdir);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* move a msg to another maildir, trying to maintain 'integrity',
|
||||
* ie. msg in 'new/' will go to new/, one in cur/ goes to cur/. be
|
||||
|
@ -811,33 +845,13 @@ mu_msg_file_move_to_maildir (const char* oldpath, const char* targetmdir,
|
|||
|
||||
g_return_val_if_fail (oldpath, FALSE);
|
||||
g_return_val_if_fail (targetmdir, FALSE);
|
||||
|
||||
if (!g_path_is_absolute(oldpath)) {
|
||||
g_set_error (err, 0, MU_ERROR_FILE,
|
||||
"source is not an absolute path: '%s'", oldpath);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
mtype = get_maildir_type (oldpath);
|
||||
if (mtype != MAILDIR_TYPE_CUR && mtype != MAILDIR_TYPE_NEW) {
|
||||
g_set_error (err, 0, MU_ERROR_FILE,
|
||||
"source is not in a 'cur' or 'new' maildir: '%s'",
|
||||
oldpath);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!g_path_is_absolute(targetmdir)) {
|
||||
g_set_error (err, 0, MU_ERROR_FILE,
|
||||
"target is not an absolute path: '%s'", targetmdir);
|
||||
if (!check_source_file (oldpath, &mtype, err))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!mu_util_check_dir (targetmdir, TRUE, TRUE)) {
|
||||
g_set_error (err, 0, MU_ERROR_FILE,
|
||||
"target is not a read-writable dir: '%s'", targetmdir);
|
||||
|
||||
if (!check_target_dir (targetmdir, err))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
newfullpath = get_new_fullpath (oldpath, targetmdir, mtype, flags);
|
||||
if (!newfullpath) {
|
||||
g_set_error (err, 0, MU_ERROR_FILE,
|
||||
|
@ -846,9 +860,7 @@ mu_msg_file_move_to_maildir (const char* oldpath, const char* targetmdir,
|
|||
}
|
||||
|
||||
/* TODO: check for oldpath == newfullpath */
|
||||
|
||||
rv = msg_move (oldpath, newfullpath, err);
|
||||
|
||||
if (!rv) {
|
||||
g_free (newfullpath);
|
||||
return NULL;
|
||||
|
|
Loading…
Reference in New Issue
Block a user