diff --git a/man/mu-find.1 b/man/mu-find.1 index 2517b56a..6b5f686d 100644 --- a/man/mu-find.1 +++ b/man/mu-find.1 @@ -1,10 +1,8 @@ -.TH MU FIND 1 "April 2011" "User Manuals" +.TH MU FIND 1 "May 2011" "User Manuals" .SH NAME -mu find \- find e-mail messages in the -.B mu -database +mu find \- find e-mail messages in the \fBmu\fR database. .SH SYNOPSIS @@ -97,10 +95,11 @@ can abbreviate \fBsubject:\fR to just \fBs:\fR. Here is the full table of the search fields and their abbreviations: .nf - cc,c CC (Carbon-Copy) recipient + cc,c Cc (carbon-copy) recipient(s) + bcc,h Bcc (blind-carbon-copy) recipient(s) from,f Message sender subject,s Message subject - to,t To: recipient + to,t To: recipient(s) maildir,m Maildir msgid,i Message-ID prio,p Message priority ('low', 'normal' or 'high') @@ -264,7 +263,8 @@ search parameters; the complete list: .nf t \fBt\fRo: recipient - c \fBc\fRc: (Carbon-Copy) recipient + c \fBc\fRc: (carbon-copy) recipient + h Bcc: (blind carbon-copy, \fBh\fRidden) recipient d Sent \fBd\fRate of the message f Message sender (\fBf\fRrom:) g Message flags (fla\fBg\fRs) @@ -288,14 +288,15 @@ specifies the field to sort the search results by, and the direction. The following fields are supported: .nf - cc,c CC (Carbon-Copy) recipient + cc,c Cc (carbon-copy) recipient(s) + bcc,h Bcc (blind-carbon-copy) recipient(s) date,d message sent date from,f message sender maildir,m maildir msgid,i message id prio,p message priority subject,s message subject - to,t To:-recipient + to,t To:-recipient(s) .fi Thus, for example, to sort messages by date, you could specify: diff --git a/src/mu-msg-contact.c b/src/mu-msg-contact.c index 250f349d..40ba8ed5 100644 --- a/src/mu-msg-contact.c +++ b/src/mu-msg-contact.c @@ -35,52 +35,54 @@ MuMsgContact * mu_msg_contact_new (const char *name, const char *address, MuMsgContactType type) { - MuMsgContact *contact; + MuMsgContact *self; g_return_val_if_fail (name, NULL); g_return_val_if_fail (address, NULL); g_return_val_if_fail (!mu_msg_contact_type_is_valid(type), NULL); - contact = g_slice_new (MuMsgContact); + self = g_slice_new (MuMsgContact); - contact->name = g_strdup(name); - contact->address = g_strdup(address); - contact->type = type; + self->name = g_strdup(name); + self->address = g_strdup(address); + self->type = type; - return contact; + return self; } void -mu_msg_contact_destroy (MuMsgContact *contacts) +mu_msg_contact_destroy (MuMsgContact *self) { - if (contacts) { - g_free ((gchar*)contacts->name); - g_free ((gchar*)contacts->address); - g_slice_free (MuMsgContact, contacts); - } + + if (!self) + return; + + g_free ((void*)self->name); + g_free ((void*)self->address); + g_slice_free (MuMsgContact, self); } static gboolean -fill_contact (MuMsgContact *contact, InternetAddress *addr, +fill_contact (MuMsgContact *self, InternetAddress *addr, MuMsgContactType ctype) { if (!addr) return FALSE; - contact->name = internet_address_get_name (addr); - contact->type = ctype; + self->name = internet_address_get_name (addr); + self->type = ctype; /* we only support internet mailbox addresses; if we don't * check, g_mime hits an assert */ - if (INTERNET_ADDRESS_IS_MAILBOX(addr)) { - contact->address = internet_address_mailbox_get_addr + if (INTERNET_ADDRESS_IS_MAILBOX(addr)) + self->address = internet_address_mailbox_get_addr (INTERNET_ADDRESS_MAILBOX(addr)); - } else - contact->address = NULL; + else + self->address = NULL; return TRUE; } @@ -110,8 +112,6 @@ address_list_foreach (InternetAddressList *addrlist, if (!(func)(&contact, user_data)) break; } - - return; } @@ -128,6 +128,7 @@ get_contacts_from (MuMsg *msg, MuMsgContactForeachFunc func, * splitting in names and addresses for us */ lst = internet_address_list_parse_string ( g_mime_message_get_sender (msg->_mime_msg)); + if (lst) { address_list_foreach (lst, MU_MSG_CONTACT_TYPE_FROM, func, user_data); diff --git a/src/mu-msg-contact.h b/src/mu-msg-contact.h index 4d32d461..a65f4142 100644 --- a/src/mu-msg-contact.h +++ b/src/mu-msg-contact.h @@ -26,9 +26,9 @@ G_BEGIN_DECLS enum _MuMsgContactType { /* Reply-To:? */ - MU_MSG_CONTACT_TYPE_TO = 0, - MU_MSG_CONTACT_TYPE_FROM, - MU_MSG_CONTACT_TYPE_CC, + MU_MSG_CONTACT_TYPE_TO = 0, + MU_MSG_CONTACT_TYPE_FROM, + MU_MSG_CONTACT_TYPE_CC, MU_MSG_CONTACT_TYPE_BCC, MU_MSG_CONTACT_TYPE_NUM @@ -39,10 +39,10 @@ typedef guint MuMsgContactType; ((MCT) < MU_MSG_CONTACT_TYPE_NUM) struct _MuMsgContact { - const char *name; /* Foo Bar */ - const char *address; /* foo@bar.cuux */ - MuMsgContactType type; /*MU_MSG_CONTACT_TYPE_{ TO, - * CC, BCC, FROM}*/ + const char *name; /* Foo Bar */ + const char *address; /* foo@bar.cuux */ + MuMsgContactType type; /* MU_MSG_CONTACT_TYPE_{ TO, + * CC, BCC, FROM} */ }; typedef struct _MuMsgContact MuMsgContact; @@ -59,7 +59,8 @@ typedef struct _MuMsgContact MuMsgContact; * needed. */ MuMsgContact *mu_msg_contact_new (const char *name, const char *address, - MuMsgContactType type); + MuMsgContactType type) + G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; /** * destroy a MuMsgConcact object diff --git a/src/mu-msg-fields.c b/src/mu-msg-fields.c index c466dfca..5f7c678b 100644 --- a/src/mu-msg-fields.c +++ b/src/mu-msg-fields.c @@ -59,6 +59,14 @@ typedef struct _MuMsgField MuMsgField; * misinterpreted by the query-preprocesser which turns queries into * lowercase */ static const MuMsgField FIELD_DATA[] = { + + { + MU_MSG_FIELD_ID_BCC, + MU_MSG_FIELD_TYPE_STRING, + "bcc" , 'h', 'H', /* 'hidden */ + FLAG_GMIME | FLAG_XAPIAN_CONTACT | FLAG_XAPIAN_VALUE + }, + { MU_MSG_FIELD_ID_BODY_TEXT, MU_MSG_FIELD_TYPE_STRING, diff --git a/src/mu-msg-fields.h b/src/mu-msg-fields.h index 91e49438..f5009f88 100644 --- a/src/mu-msg-fields.h +++ b/src/mu-msg-fields.h @@ -26,8 +26,10 @@ G_BEGIN_DECLS /* don't change the order, add new types at the end, as these numbers * are used in the database */ -enum _MuMsgFieldId { - MU_MSG_FIELD_ID_BODY_TEXT = 0, +enum _MuMsgFieldId { + + MU_MSG_FIELD_ID_BCC = 0, + MU_MSG_FIELD_ID_BODY_TEXT, MU_MSG_FIELD_ID_BODY_HTML, MU_MSG_FIELD_ID_CC, MU_MSG_FIELD_ID_DATE, diff --git a/src/mu-msg-iter.cc b/src/mu-msg-iter.cc index 8598a0ab..341e9e5d 100644 --- a/src/mu-msg-iter.cc +++ b/src/mu-msg-iter.cc @@ -287,6 +287,13 @@ mu_msg_iter_get_cc (MuMsgIter *iter) return get_field (iter, MU_MSG_FIELD_ID_CC); } +const char* +mu_msg_iter_get_bcc (MuMsgIter *iter) +{ + g_return_val_if_fail (!mu_msg_iter_is_done(iter), NULL); + return get_field (iter, MU_MSG_FIELD_ID_BCC); +} + const char* mu_msg_iter_get_subject (MuMsgIter *iter) diff --git a/src/mu-msg-iter.h b/src/mu-msg-iter.h index 1aa36f2d..506f0da6 100644 --- a/src/mu-msg-iter.h +++ b/src/mu-msg-iter.h @@ -205,7 +205,7 @@ const char* mu_msg_iter_get_to (MuMsgIter *iter); /** - * get the message recipient (Cc:) of the message + * get the 'carbon-copy' recipient(s) (Cc:) of the message * * @param iter a valid MuMsgIter iterator * @@ -213,6 +213,17 @@ const char* mu_msg_iter_get_to (MuMsgIter *iter); */ const char* mu_msg_iter_get_cc (MuMsgIter *iter); + +/** + * get the 'blind carbon-copy' message recipient(s) (Bcc:) of the + * message + * + * @param iter a valid MuMsgIter iterator + * + * @return the Bcc-recipient(s), or NULL in case of error + */ +const char* mu_msg_iter_get_bcc (MuMsgIter *iter); + /** * get the subject of the message * diff --git a/src/mu-msg-priv.h b/src/mu-msg-priv.h index 3a085243..cd5255f8 100644 --- a/src/mu-msg-priv.h +++ b/src/mu-msg-priv.h @@ -38,6 +38,7 @@ enum _StringFields { TO_FIELD, /* To: */ CC_FIELD, /* Cc: */ + BCC_FIELD, /* Bcc: */ PATH_FIELD, /* full path */ MDIR_FIELD, /* the maildir */ diff --git a/src/mu-msg.c b/src/mu-msg.c index 37b9b719..51c4ed14 100644 --- a/src/mu-msg.c +++ b/src/mu-msg.c @@ -292,7 +292,7 @@ get_recipient (MuMsg *msg, GMimeRecipientType rtype, StringFields field) * internet_address_list_to_string? */ recep = (char*)internet_address_list_to_string (receps, TRUE); - if (recep && recep[0]=='\0') + if (mu_str_is_empty(recep)) g_free (recep); else msg->_fields[field] = recep; @@ -316,6 +316,13 @@ mu_msg_get_cc (MuMsg *msg) return get_recipient (msg, GMIME_RECIPIENT_TYPE_CC, CC_FIELD); } +const char* +mu_msg_get_bcc (MuMsg *msg) +{ + g_return_val_if_fail (msg, NULL); + return get_recipient (msg, GMIME_RECIPIENT_TYPE_BCC, BCC_FIELD); +} + time_t mu_msg_get_date (MuMsg *msg) @@ -643,7 +650,14 @@ convert_to_utf8 (GMimePart *part, char *buffer) { GMimeContentType *ctype; const char* charset; - + char *cur; + + /* optimization: if the buffer is plain ascii, no conversion + * is done... */ + for (cur = buffer; *cur && *cur < 0x80; ++cur); + if (*cur == '\0') + return buffer; + ctype = g_mime_object_get_content_type (GMIME_OBJECT(part)); g_return_val_if_fail (GMIME_IS_CONTENT_TYPE(ctype), NULL); @@ -910,6 +924,7 @@ mu_msg_get_field_string (MuMsg *msg, MuMsgFieldId mfid) g_return_val_if_fail (msg, NULL); switch (mfid) { + case MU_MSG_FIELD_ID_BCC: return mu_msg_get_bcc (msg); case MU_MSG_FIELD_ID_BODY_TEXT: return mu_msg_get_body_text (msg); case MU_MSG_FIELD_ID_BODY_HTML: return mu_msg_get_body_html (msg); case MU_MSG_FIELD_ID_CC: return mu_msg_get_cc (msg); diff --git a/src/mu-msg.h b/src/mu-msg.h index 5f7d58d7..5c414ce8 100644 --- a/src/mu-msg.h +++ b/src/mu-msg.h @@ -160,6 +160,19 @@ const char* mu_msg_get_to (MuMsg *msg); */ const char* mu_msg_get_cc (MuMsg *msg); + +/** + * get the blind carbon-copy recipients (Bcc:) of this message; this + * field usually only appears in outgoing messages + * + * @param msg a valid MuMsg* instance + * + * @return the Bcc: recipients of this Message or NULL in case of + * error or if there are no such recipients. the returned string + * should *not* be modified or freed. + */ +const char* mu_msg_get_bcc (MuMsg *msg); + /** * get the file system path of this message * diff --git a/src/mu-store.cc b/src/mu-store.cc index 94d3ea32..fb88c802 100644 --- a/src/mu-store.cc +++ b/src/mu-store.cc @@ -467,7 +467,9 @@ xapian_pfx (MuMsgContact *contact) return prefix(MU_MSG_FIELD_ID_FROM); case MU_MSG_CONTACT_TYPE_CC: return prefix(MU_MSG_FIELD_ID_CC); - default: /* dont;t support other type (e.g, bcc) */ + case MU_MSG_CONTACT_TYPE_BCC: + return prefix(MU_MSG_FIELD_ID_BCC); + default: g_warning ("unsupported contact type %u", (unsigned)contact->type); return empty;