* mu-cmd-find.c, mu-msg-sexp.c, mu-msg.c: refactor for 'make line33' check
This commit is contained in:
@ -455,8 +455,7 @@ output_links (MuMsgIter *iter, const char* linksdir,
|
|||||||
if (!create_linksdir_maybe (linksdir, clearlinks))
|
if (!create_linksdir_maybe (linksdir, clearlinks))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
for (myiter = iter, errseen = FALSE, mycount = 0;
|
for (myiter = iter, errseen = FALSE, mycount = 0; !mu_msg_iter_is_done (myiter);
|
||||||
!mu_msg_iter_is_done (myiter);
|
|
||||||
mu_msg_iter_next (myiter)) {
|
mu_msg_iter_next (myiter)) {
|
||||||
|
|
||||||
MuMsg *msg;
|
MuMsg *msg;
|
||||||
@ -477,8 +476,7 @@ output_links (MuMsgIter *iter, const char* linksdir,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (errseen)
|
if (errseen)
|
||||||
g_warning ("error linking some of the messages; maybe the "
|
g_warning ("error linking some of the messages");
|
||||||
"database needs to be updated");
|
|
||||||
|
|
||||||
if (count)
|
if (count)
|
||||||
*count = mycount;
|
*count = mycount;
|
||||||
@ -754,6 +752,25 @@ output_sexp (MuMsgIter *iter, gboolean include_unreadable, size_t *count)
|
|||||||
return TRUE;
|
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
|
static gboolean
|
||||||
output_xml (MuMsgIter *iter, gboolean include_unreadable, size_t *count)
|
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);
|
for (myiter = iter, mycount = 0; !mu_msg_iter_is_done (myiter);
|
||||||
mu_msg_iter_next (myiter)) {
|
mu_msg_iter_next (myiter)) {
|
||||||
|
|
||||||
MuMsg *msg;
|
MuMsg *msg;
|
||||||
|
|
||||||
msg = mu_msg_iter_get_msg (iter, NULL); /* don't unref */
|
msg = mu_msg_iter_get_msg (iter, NULL); /* don't unref */
|
||||||
if (!msg)
|
if (!msg)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -778,24 +794,11 @@ output_xml (MuMsgIter *iter, gboolean include_unreadable, size_t *count)
|
|||||||
* readable (ie, live also outside the database) */
|
* readable (ie, live also outside the database) */
|
||||||
if (!include_unreadable && !mu_msg_is_readable (msg))
|
if (!include_unreadable && !mu_msg_is_readable (msg))
|
||||||
continue;
|
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;
|
++mycount;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_print ("</messages>\n");
|
g_print ("</messages>\n");
|
||||||
|
|
||||||
if (count)
|
if (count)
|
||||||
|
|||||||
@ -91,45 +91,38 @@ static gboolean
|
|||||||
each_contact (MuMsgContact *c, ContactData *cdata)
|
each_contact (MuMsgContact *c, ContactData *cdata)
|
||||||
{
|
{
|
||||||
char *pair;
|
char *pair;
|
||||||
|
|
||||||
pair = get_name_addr_pair (c);
|
|
||||||
|
|
||||||
if (mu_msg_contact_type (c) == MU_MSG_CONTACT_TYPE_FROM) {
|
if (mu_msg_contact_type (c) == MU_MSG_CONTACT_TYPE_FROM) {
|
||||||
if (!cdata->from)
|
if (!cdata->from)
|
||||||
g_string_append (cdata->gstr, "\t:from (");
|
g_string_append (cdata->gstr, "\t:from (");
|
||||||
g_string_append (cdata->gstr, pair);
|
|
||||||
cdata->from = TRUE;
|
cdata->from = TRUE;
|
||||||
}
|
|
||||||
|
} else if (mu_msg_contact_type (c) == MU_MSG_CONTACT_TYPE_TO) {
|
||||||
if (mu_msg_contact_type (c) == MU_MSG_CONTACT_TYPE_TO) {
|
|
||||||
if (!cdata->to)
|
if (!cdata->to)
|
||||||
g_string_append_printf (cdata->gstr,"%s\t:to (",
|
g_string_append_printf (cdata->gstr,"%s\t:to (",
|
||||||
cdata->from ? ")\n" : "");
|
cdata->from ? ")\n" : "");
|
||||||
g_string_append (cdata->gstr, pair);
|
|
||||||
cdata->to = TRUE;
|
cdata->to = TRUE;
|
||||||
}
|
|
||||||
|
} else if (mu_msg_contact_type (c) == MU_MSG_CONTACT_TYPE_CC) {
|
||||||
if (mu_msg_contact_type (c) == MU_MSG_CONTACT_TYPE_CC) {
|
|
||||||
if (!cdata->cc)
|
if (!cdata->cc)
|
||||||
g_string_append_printf (cdata->gstr,"%s\t:cc (",
|
g_string_append_printf (cdata->gstr,"%s\t:cc (",
|
||||||
cdata->from||cdata->to ?
|
cdata->from||cdata->to ?
|
||||||
")\n" : "");
|
")\n" : "");
|
||||||
g_string_append (cdata->gstr, pair);
|
|
||||||
cdata->cc = TRUE;
|
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)
|
if (!cdata->bcc)
|
||||||
g_string_append_printf
|
g_string_append_printf
|
||||||
(cdata->gstr, "%s\t:bcc (",
|
(cdata->gstr, "%s\t:bcc (",
|
||||||
cdata->from||cdata->to||cdata->cc ?
|
cdata->from||cdata->to||cdata->cc ? ")\n":"");
|
||||||
")\n" : "");
|
|
||||||
g_string_append (cdata->gstr, pair);
|
|
||||||
cdata->bcc = TRUE;
|
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);
|
g_free (pair);
|
||||||
|
|
||||||
return TRUE;
|
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*
|
char*
|
||||||
mu_msg_to_sexp (MuMsg *msg, gboolean dbonly)
|
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));
|
"subject", mu_msg_get_subject (msg));
|
||||||
|
|
||||||
t = mu_msg_get_date (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),
|
"\t:date (%u %u 0)\n", (unsigned)(t >> 16),
|
||||||
(unsigned)(t & 0xffff));
|
(unsigned)(t & 0xffff));
|
||||||
g_string_append_printf (gstr, "\t:size %u\n",
|
g_string_append_printf (gstr, "\t:size %u\n",
|
||||||
(unsigned) mu_msg_get_size (msg));
|
(unsigned) mu_msg_get_size (msg));
|
||||||
|
|
||||||
|
|
||||||
append_sexp_attr (gstr, "message-id", mu_msg_get_msgid (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, "path", mu_msg_get_path (msg));
|
||||||
append_sexp_attr (gstr, "maildir", mu_msg_get_maildir (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);
|
append_sexp_flags (gstr, msg);
|
||||||
|
|
||||||
if (!dbonly) {
|
/* file attr things can only be gotten from the file (ie., mu
|
||||||
append_sexp_attachments (gstr, msg);
|
* view), not from the database (mu find) */
|
||||||
|
if (!dbonly)
|
||||||
append_sexp_attr (gstr, "reply-to",
|
append_sexp_message_file_attr (gstr, msg);
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
g_string_append (gstr, ")\n;;eom\n");
|
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;
|
== 0) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum _MaildirType {
|
enum _MaildirType {
|
||||||
MAILDIR_TYPE_CUR,
|
MAILDIR_TYPE_CUR,
|
||||||
MAILDIR_TYPE_NEW,
|
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',
|
* 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
|
* 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 (oldpath, FALSE);
|
||||||
g_return_val_if_fail (targetmdir, 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)) {
|
if (!check_source_file (oldpath, &mtype, err))
|
||||||
g_set_error (err, 0, MU_ERROR_FILE,
|
|
||||||
"target is not an absolute path: '%s'", targetmdir);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
|
if (!check_target_dir (targetmdir, err))
|
||||||
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 FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
newfullpath = get_new_fullpath (oldpath, targetmdir, mtype, flags);
|
newfullpath = get_new_fullpath (oldpath, targetmdir, mtype, flags);
|
||||||
if (!newfullpath) {
|
if (!newfullpath) {
|
||||||
g_set_error (err, 0, MU_ERROR_FILE,
|
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 */
|
/* TODO: check for oldpath == newfullpath */
|
||||||
|
|
||||||
rv = msg_move (oldpath, newfullpath, err);
|
rv = msg_move (oldpath, newfullpath, err);
|
||||||
|
|
||||||
if (!rv) {
|
if (!rv) {
|
||||||
g_free (newfullpath);
|
g_free (newfullpath);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user