From 8ab3ff1fecc7e0fcf5f1439f449282947906a1f8 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sat, 3 Sep 2011 10:48:36 +0300 Subject: [PATCH] * mu-msg-doc.cc, mu-msg-iter.cc, mu-msg.h: cosmetics --- src/mu-msg-doc.cc | 34 +++++----- src/mu-msg-iter.cc | 8 ++- src/mu-msg.h | 150 ++++++++++++++++++++++----------------------- 3 files changed, 97 insertions(+), 95 deletions(-) diff --git a/src/mu-msg-doc.cc b/src/mu-msg-doc.cc index 8bdde617..8ffdc5fb 100644 --- a/src/mu-msg-doc.cc +++ b/src/mu-msg-doc.cc @@ -30,12 +30,12 @@ #include "mu-date.h" struct _MuMsgDoc { - _MuMsgDoc (Xapian::Document *doc) : _doc (doc) {} - ~_MuMsgDoc () { delete _doc; } + + _MuMsgDoc (Xapian::Document *doc): _doc (doc) { } + ~_MuMsgDoc () { delete _doc; } const Xapian::Document doc() const { return *_doc; } -private: - Xapian::Document *_doc; - +private: + Xapian::Document *_doc; }; @@ -43,10 +43,10 @@ MuMsgDoc* mu_msg_doc_new (XapianDocument *doc, GError **err) { g_return_val_if_fail (doc, NULL); - + try { return new MuMsgDoc ((Xapian::Document*)doc); - + } MU_XAPIAN_CATCH_BLOCK_G_ERROR_RETURN(err, MU_ERROR_XAPIAN, NULL); return FALSE; @@ -57,7 +57,7 @@ mu_msg_doc_destroy (MuMsgDoc *self) { try { delete self; - + } MU_XAPIAN_CATCH_BLOCK; } @@ -71,11 +71,11 @@ mu_msg_doc_get_str_field (MuMsgDoc *self, MuMsgFieldId mfid, g_return_val_if_fail (mu_msg_field_is_string(mfid), NULL); *do_free = TRUE; - + try { const std::string s (self->doc().get_value(mfid)); return s.empty() ? NULL : g_strdup (s.c_str()); - + } MU_XAPIAN_CATCH_BLOCK_RETURN(NULL); } @@ -87,14 +87,14 @@ mu_msg_doc_get_str_list_field (MuMsgDoc *self, MuMsgFieldId mfid, g_return_val_if_fail (self, NULL); g_return_val_if_fail (mu_msg_field_id_is_valid(mfid), NULL); g_return_val_if_fail (mu_msg_field_is_string_list(mfid), NULL); - + *do_free = TRUE; - + try { /* return a comma-separated string as a GSList */ const std::string s (self->doc().get_value(mfid)); return s.empty() ? NULL : mu_str_to_list(s.c_str(),',',TRUE); - + } MU_XAPIAN_CATCH_BLOCK_RETURN(NULL); } @@ -105,9 +105,9 @@ mu_msg_doc_get_num_field (MuMsgDoc *self, MuMsgFieldId mfid) g_return_val_if_fail (self, -1); g_return_val_if_fail (mu_msg_field_id_is_valid(mfid), -1); g_return_val_if_fail (mu_msg_field_is_numeric(mfid), -1); - + /* date is a special case, because we store dates as - * strings */ + * strings */ try { const std::string s (self->doc().get_value(mfid)); if (s.empty()) @@ -119,8 +119,8 @@ mu_msg_doc_get_num_field (MuMsgDoc *self, MuMsgFieldId mfid) } else { return static_cast(Xapian::sortable_unserialise(s)); } - - } MU_XAPIAN_CATCH_BLOCK_RETURN(-1); + + } MU_XAPIAN_CATCH_BLOCK_RETURN(-1); } diff --git a/src/mu-msg-iter.cc b/src/mu-msg-iter.cc index 1d3af73a..a6d55bc3 100644 --- a/src/mu-msg-iter.cc +++ b/src/mu-msg-iter.cc @@ -53,7 +53,7 @@ struct _MuMsgIter { public: _MuMsgIter (Xapian::Enquire &enq, size_t maxnum, gboolean threads, MuMsgFieldId sortfield): - _enq(enq), _thread_hash (0), _msg(0) { + _enq(enq), _thread_hash (0), _msg(0) { _matches = _enq.get_mset (0, maxnum); @@ -80,10 +80,11 @@ public: ~_MuMsgIter () { if (_thread_hash) g_hash_table_destroy (_thread_hash); + set_msg (NULL); } - const Xapian::Enquire& enquire() { return _enq; } + const Xapian::Enquire& enquire() const { return _enq; } Xapian::MSet& matches() { return _matches; } Xapian::MSet::const_iterator cursor () const { return _cursor; } @@ -98,6 +99,7 @@ public: mu_msg_unref (_msg); return _msg = msg; } + private: const Xapian::Enquire _enq; Xapian::MSet _matches; @@ -146,7 +148,7 @@ mu_msg_iter_get_msg_floating (MuMsgIter *iter) docp = new Xapian::Document(iter->cursor().get_document()); err = NULL; - msg = iter->set_msg (mu_msg_new_from_doc ((XapianDocument*)docp, &err)); + msg = iter->set_msg (mu_msg_new_from_doc((XapianDocument*)docp, &err)); if (!msg) MU_HANDLE_G_ERROR(err); diff --git a/src/mu-msg.h b/src/mu-msg.h index 6c58b104..734a08f2 100644 --- a/src/mu-msg.h +++ b/src/mu-msg.h @@ -6,16 +6,16 @@ ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 3 of the License, or ** (at your option) any later version. -** +** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. -** +** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** +** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** */ #ifndef __MU_MSG_H__ @@ -24,7 +24,7 @@ #include #include #include -#include /* for MuResult, MuError and XapianDocument */ +#include /* for MuError and XapianDocument */ G_BEGIN_DECLS @@ -43,7 +43,7 @@ typedef struct _MuMsg MuMsg; * @param err receive error information (MU_ERROR_FILE or * MU_ERROR_GMIME), or NULL. There will only be err info if the * function returns NULL - * + * * @return a new MuMsg instance or NULL in case of error; call * mu_msg_unref when done with this message */ @@ -55,23 +55,23 @@ MuMsg *mu_msg_new_from_file (const char* filepath, const char *maildir, /** * create a new MuMsg* instance based on a Xapian::Document * + * @param store a MuStore ptr * @param doc a ptr to a Xapian::Document (but cast to XapianDocument, * because this is C not C++). MuMsg takes _ownership_ of this pointer; * don't touch it afterwards * @param err receive error information, or NULL. There * will only be err info if the function returns NULL - * + * * @return a new MuMsg instance or NULL in case of error; call * mu_msg_unref when done with this message */ MuMsg *mu_msg_new_from_doc (XapianDocument* doc, GError **err) - G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; - + G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; /** * increase the reference count for this message - * + * * @param msg a message * * @return the message with its reference count increased, or NULL in @@ -82,7 +82,7 @@ MuMsg *mu_msg_ref (MuMsg *msg); /** * decrease the reference count for this message. if the reference * count reaches 0, the message will be destroyed. - * + * * @param msg a message */ void mu_msg_unref (MuMsg *msg); @@ -92,7 +92,7 @@ void mu_msg_unref (MuMsg *msg); /** * cache the values from the backend (file or db), so we don't the * backend anymore - * + * * @param self a message */ void mu_msg_cache_values (MuMsg *self); @@ -102,7 +102,7 @@ void mu_msg_cache_values (MuMsg *self); * get the plain text body of this message * * @param msg a valid MuMsg* instance - * + * * @return the plain text body or NULL in case of error or if there is no * such body. the returned string should *not* be modified or freed. * The returned data is in UTF8 or NULL. @@ -114,7 +114,7 @@ const char* mu_msg_get_body_text (MuMsg *msg); * get the html body of this message * * @param msg a valid MuMsg* instance - * + * * @return the html body or NULL in case of error or if there is no * such body. the returned string should *not* be modified or freed. */ @@ -124,8 +124,8 @@ const char* mu_msg_get_body_html (MuMsg *msg); * get the sender (From:) of this message * * @param msg a valid MuMsg* instance - * - * @return the sender of this Message or NULL in case of error or if there + * + * @return the sender of this Message or NULL in case of error or if there * is no sender. the returned string should *not* be modified or freed. */ const char* mu_msg_get_from (MuMsg *msg); @@ -135,8 +135,8 @@ const char* mu_msg_get_from (MuMsg *msg); * get the recipients (To:) of this message * * @param msg a valid MuMsg* instance - * - * @return the sender of this Message or NULL in case of error or if there + * + * @return the sender of this Message or NULL in case of error or if there * are no recipients. the returned string should *not* be modified or freed. */ const char* mu_msg_get_to (MuMsg *msg); @@ -146,9 +146,9 @@ const char* mu_msg_get_to (MuMsg *msg); * get the carbon-copy recipients (Cc:) of this message * * @param msg a valid MuMsg* instance - * - * @return the Cc: recipients of this Message or NULL in case of error or if - * there are no such recipients. the returned string should *not* be modified + * + * @return the Cc: 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_cc (MuMsg *msg); @@ -159,7 +159,7 @@ const char* mu_msg_get_cc (MuMsg *msg); * 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. @@ -170,8 +170,8 @@ const char* mu_msg_get_bcc (MuMsg *msg); * get the file system path of this message * * @param msg a valid MuMsg* instance - * - * @return the path of this Message or NULL in case of error. + * + * @return the path of this Message or NULL in case of error. * the returned string should *not* be modified or freed. */ const char* mu_msg_get_path (MuMsg *msg); @@ -182,7 +182,7 @@ const char* mu_msg_get_path (MuMsg *msg); * ~/Maildir/foo/bar/cur/msg, the maildir would be foo/bar * * @param msg a valid MuMsg* instance - * + * * @return the maildir requested or NULL in case of error. The returned * string should *not* be modified or freed. */ @@ -193,8 +193,8 @@ const char* mu_msg_get_maildir (MuMsg *msg); * get the subject of this message * * @param msg a valid MuMsg* instance - * - * @return the subject of this Message or NULL in case of error or if there + * + * @return the subject of this Message or NULL in case of error or if there * is no subject. the returned string should *not* be modified or freed. */ const char* mu_msg_get_subject (MuMsg *msg); @@ -203,7 +203,7 @@ const char* mu_msg_get_subject (MuMsg *msg); * get the Message-Id of this message * * @param msg a valid MuMsg* instance - * + * * @return the Message-Id of this Message (without the enclosing <>) * or NULL in case of error or if there is none. the returned string * should *not* be modified or freed. @@ -216,19 +216,19 @@ const char* mu_msg_get_msgid (MuMsg *msg); * * @param msg a valid MuMsg* instance * @header the header requested - * - * @return the header requested or NULL in case of error or if there + * + * @return the header requested or NULL in case of error or if there * is no such header. the returned string should *not* be modified or freed. */ -const char* mu_msg_get_header (MuMsg *msg, +const char* mu_msg_get_header (MuMsg *msg, const char* header); /** * get the message date/time (the Date: field) as time_t, using UTC * * @param msg a valid MuMsg* instance - * - * @return message date/time or 0 in case of error or if there + * + * @return message date/time or 0 in case of error or if there * is no such header. */ time_t mu_msg_get_date (MuMsg *msg); @@ -237,7 +237,7 @@ time_t mu_msg_get_date (MuMsg *msg); * get the flags for this message * * @param msg valid MuMsg* instance - * + * * @return the fileflags as logically OR'd #Mu MsgFlags or 0 if * there are none. */ @@ -248,18 +248,18 @@ MuFlags mu_msg_get_flags (MuMsg *msg); * get the file size in bytes of this message * * @param msg a valid MuMsg* instance - * - * @return the filesize + * + * @return the filesize */ size_t mu_msg_get_size (MuMsg *msg); /** * get some field value as string - * + * * @param msg a valid MuMsg instance * @param field the field to retrieve; it must be a string-typed field - * + * * @return a string that should not be freed */ const char* mu_msg_get_field_string (MuMsg *msg, MuMsgFieldId mfid); @@ -267,20 +267,20 @@ const char* mu_msg_get_field_string (MuMsg *msg, MuMsgFieldId mfid); /** * get some field value as string-list - * + * * @param msg a valid MuMsg instance * @param field the field to retrieve; it must be a string-list-typed field - * + * * @return a list that should not be freed */ const GSList* mu_msg_get_field_string_list (MuMsg *self, MuMsgFieldId mfid); /** * get some field value as string - * + * * @param msg a valid MuMsg instance * @param field the field to retrieve; it must be a numeric field - * + * * @return a string that should not be freed */ gint64 mu_msg_get_field_numeric (MuMsg *msg, MuMsgFieldId mfid); @@ -293,16 +293,16 @@ gint64 mu_msg_get_field_numeric (MuMsg *msg, MuMsgFieldId mfid); * MU_MSG_PRIO_NORMAL is assumed * * @param msg a valid MuMsg* instance - * + * * @return the message priority (!= 0) or 0 in case of error */ MuMsgPrio mu_msg_get_prio (MuMsg *msg); /** - * get the timestamp (mtime) for the file containing this message + * get the timestamp (mtime) for the file containing this message * * @param msg a valid MuMsg* instance - * + * * @return the timestamp or 0 in case of error */ time_t mu_msg_get_timestamp (MuMsg *msg); @@ -312,10 +312,10 @@ time_t mu_msg_get_timestamp (MuMsg *msg); /** * get a specific header from the message. This value will _not_ be * cached - * + * * @param self a MuMsg instance * @param header a specific header (like 'X-Mailer' or 'Organization') - * + * * @return a header string which is valid as long as this MuMsg is */ const char* mu_msg_get_header (MuMsg *self, const char *header); @@ -327,18 +327,18 @@ const char* mu_msg_get_header (MuMsg *self, const char *header); * one; this final one is typically the 'In-reply-to' field. Note, any * reference (message-id) will appear at most once, duplicates are * filtered out. - * + * * @param msg a valid MuMsg - * + * * @return a list with the references for this msg. Don't modify/free */ const GSList* mu_msg_get_references (MuMsg *msg); /** * get the list of tags (ie., X-Label) - * + * * @param msg a valid MuMsg - * + * * @return a list with the tags for this msg. Don't modify/free */ const GSList* mu_msg_get_tags (MuMsg *self); @@ -346,11 +346,11 @@ const GSList* mu_msg_get_tags (MuMsg *self); /** * compare two messages for sorting - * + * * @param m1 a message * @param m2 another message * @param mfid the message to use for the comparison - * + * * @return negative if m1 is smaller, positive if m1 is smaller, 0 if * they are equal */ @@ -359,10 +359,10 @@ int mu_msg_cmp (MuMsg *m1, MuMsg *m2, MuMsgFieldId mfid); /** - * check whether there there's a readable file behind this message - * + * check whether there there's a readable file behind this message + * * @param self a MuMsg* - * + * * @return TRUE if the message file is readable, FALSE otherwise */ gboolean mu_msg_is_readable (MuMsg *self); @@ -374,13 +374,13 @@ struct _MuMsgIterThreadInfo; /** * convert the msg to a Lisp symbolic expression (for further processing in * e.g. emacs) - * + * * @param msg a valid message * @param ti thread info for the current message, or NULL * @param dbonly if TRUE, only include message fields which can be * obtained from the database (this is much faster if the MuMsg is * database-backed, so no file needs to be opened) - * + * * @return a string with the sexp (free with g_free) or NULL in case of error */ char* mu_msg_to_sexp (MuMsg *msg, const struct _MuMsgIterThreadInfo *ti, @@ -388,7 +388,7 @@ char* mu_msg_to_sexp (MuMsg *msg, const struct _MuMsgIterThreadInfo *ti, /** * move a message to another maildir - * + * * @param msg a message with an existing file system path in an actual * maildir * @param targetmdir the target maildir; note that this the base-level @@ -404,8 +404,8 @@ char* mu_msg_to_sexp (MuMsg *msg, const struct _MuMsgIterThreadInfo *ti, * @param err (may be NULL) may contain error information; note if the * function return FALSE, err is not set for all error condition * (ie. not for parameter error - * - * @return TRUE if it worked, FALSE otherwise + * + * @return TRUE if it worked, FALSE otherwise */ gboolean mu_msg_move_to_maildir (MuMsg *msg, const char* targetmdir, MuFlags flags, gboolean ignore_dups, @@ -414,10 +414,10 @@ gboolean mu_msg_move_to_maildir (MuMsg *msg, const char* targetmdir, enum _MuMsgContactType { /* Reply-To:? */ MU_MSG_CONTACT_TYPE_TO = 0, - MU_MSG_CONTACT_TYPE_FROM, - MU_MSG_CONTACT_TYPE_CC, + MU_MSG_CONTACT_TYPE_FROM, + MU_MSG_CONTACT_TYPE_CC, MU_MSG_CONTACT_TYPE_BCC, - + MU_MSG_CONTACT_TYPE_NUM }; typedef guint MuMsgContactType; @@ -429,18 +429,18 @@ struct _MuMsgContact { const char *name; /* Foo Bar */ const char *address; /* foo@bar.cuux */ MuMsgContactType type; /* MU_MSG_CONTACT_TYPE_{ TO, - * CC, BCC, FROM} */ + * CC, BCC, FROM} */ }; typedef struct _MuMsgContact MuMsgContact; /** * create a new MuMsgContact object; note, in many case, this is not * needed, any a stack-allocated struct can be uses. - * + * * @param name the name of the contact * @param address the e-mail address of the contact * @param type the type of contact: cc, bcc, from, to - * + * * @return a newly allocated MuMsgConcact or NULL in case of * error. use mu_msg_contact_destroy to destroy it when it's no longer * needed. @@ -451,34 +451,34 @@ MuMsgContact *mu_msg_contact_new (const char *name, const char *address, /** * destroy a MuMsgConcact object - * + * * @param contact a contact object, or NULL */ void mu_msg_contact_destroy (MuMsgContact *contact); /** * macro to get the name of a contact - * + * * @param ct a MuMsgContact - * + * * @return the name */ #define mu_msg_contact_name(ct) ((ct)->name) /** * macro to get the address of a contact - * + * * @param ct a MuMsgContact - * + * * @return the address */ #define mu_msg_contact_address(ct) ((ct)->address) /** * macro to get the contact type - * + * * @param ct a MuMsgContact - * + * * @return the contact type */ #define mu_msg_contact_type(ct) ((ct)->type) @@ -503,7 +503,7 @@ typedef gboolean (*MuMsgContactForeachFunc) (MuMsgContact* contact, * @param func a callback function to call for each contact; when * the callback does not return TRUE, it won't be called again * @param user_data a user-provide pointer that will be passed to the callback - * + * */ void mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func, gpointer user_data);