Re: A systematic way of handling Xapian lock errors?
[notmuch-archives.git] / 8b / 9e355197ffd2efbe3b6d7d33044375fb1fd4c4
1 Return-Path: <stefan@datenfreihafen.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id E4203431FBF\r
6         for <notmuch@notmuchmail.org>; Sat, 21 Nov 2009 16:11:31 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id k6PahtnYXl0O for <notmuch@notmuchmail.org>;\r
11         Sat, 21 Nov 2009 16:11:30 -0800 (PST)\r
12 Received: from sirius.lasnet.de (sirius.lasnet.de [78.47.116.19])\r
13         by olra.theworths.org (Postfix) with ESMTP id 1BAB6431FBC\r
14         for <notmuch@notmuchmail.org>; Sat, 21 Nov 2009 16:11:30 -0800 (PST)\r
15 Received: from p5b034af6.dip.t-dialin.net ([91.3.74.246] helo=excalibur)\r
16         by sirius.lasnet.de with esmtpsa \r
17         (Cipher TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.63 #1)\r
18         id 1NC02v-0000t5-LF by authid <stefan@sostec.de> with cram_md5;\r
19         Sun, 22 Nov 2009 01:11:29 +0100\r
20 Received: from stefan by excalibur with local (Exim 4.69)\r
21         (envelope-from <stefan@excalibur.local>)\r
22         id 1NC02u-0001Dj-V9; Sun, 22 Nov 2009 01:11:16 +0100\r
23 From: Stefan Schmidt <stefan@datenfreihafen.org>\r
24 To: notmuch@notmuchmail.org\r
25 Date: Sun, 22 Nov 2009 01:11:00 +0100\r
26 Message-Id: <1258848661-4660-1-git-send-email-stefan@datenfreihafen.org>\r
27 X-Mailer: git-send-email 1.6.5.3\r
28 In-Reply-To: <yes>\r
29 References: <yes>\r
30 Subject: [notmuch] [PATCH 1/2] lib/message: Add function to get maildir\r
31         flags.\r
32 X-BeenThere: notmuch@notmuchmail.org\r
33 X-Mailman-Version: 2.1.12\r
34 Precedence: list\r
35 List-Id: "Use and development of the notmuch mail system."\r
36         <notmuch.notmuchmail.org>\r
37 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
38         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
39 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
40 List-Post: <mailto:notmuch@notmuchmail.org>\r
41 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
42 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
43         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
44 X-List-Received-Date: Sun, 22 Nov 2009 00:11:32 -0000\r
45 \r
46 With notmuch_message_get_flags() we gain the information if the message was\r
47 flagged as read, draft, trashed, etc. Handy for big mail spooles that were used\r
48 with another mailer.\r
49 \r
50 Signed-off-by: Stefan Schmidt <stefan@datenfreihafen.org>\r
51 ---\r
52  lib/message.cc |   26 ++++++++++++++++++++++++++\r
53  lib/notmuch.h  |   10 ++++++++++\r
54  2 files changed, 36 insertions(+), 0 deletions(-)\r
55 \r
56 diff --git a/lib/message.cc b/lib/message.cc\r
57 index 069cedb..9bec61e 100644\r
58 --- a/lib/message.cc\r
59 +++ b/lib/message.cc\r
60 @@ -35,6 +35,7 @@ struct _notmuch_message {\r
61      char *thread_id;\r
62      char *in_reply_to;\r
63      char *filename;\r
64 +    char *flags;\r
65      notmuch_message_file_t *message_file;\r
66      notmuch_message_list_t *replies;\r
67  \r
68 @@ -114,6 +115,7 @@ _notmuch_message_create (const void *talloc_owner,\r
69      message->thread_id = NULL;\r
70      message->in_reply_to = NULL;\r
71      message->filename = NULL;\r
72 +    message->flags = NULL;\r
73      message->message_file = NULL;\r
74  \r
75      message->replies = _notmuch_message_list_create (message);\r
76 @@ -438,6 +440,30 @@ notmuch_message_get_filename (notmuch_message_t *message)\r
77      return message->filename;\r
78  }\r
79  \r
80 +const char *\r
81 +notmuch_message_get_flags (notmuch_message_t *message)\r
82 +{\r
83 +    std::string filename_str, flags;\r
84 +    size_t position;\r
85 +    const char *db_path;\r
86 +\r
87 +    if (message->flags)\r
88 +       return message->flags;\r
89 +\r
90 +    filename_str = message->doc.get_data ();\r
91 +    db_path = notmuch_database_get_path (message->notmuch);\r
92 +\r
93 +    if (filename_str[0] != '/')\r
94 +       filename_str.insert (0, db_path);\r
95 +\r
96 +    /* Flags are everything behind ":" */\r
97 +    position = filename_str.find (":");\r
98 +    flags = filename_str.substr (position + 3); /* We don't want :2, */\r
99 +    message->flags = talloc_strdup (message, flags.c_str ());\r
100 +\r
101 +    return message->flags;\r
102 +}\r
103 +\r
104  time_t\r
105  notmuch_message_get_date (notmuch_message_t *message)\r
106  {\r
107 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
108 index a61cd02..1da5dfd 100644\r
109 --- a/lib/notmuch.h\r
110 +++ b/lib/notmuch.h\r
111 @@ -694,6 +694,16 @@ notmuch_message_get_replies (notmuch_message_t *message);\r
112  const char *\r
113  notmuch_message_get_filename (notmuch_message_t *message);\r
114  \r
115 +/* Get the maildir flags for the email corresponding to 'message'.\r
116 + *\r
117 + * The returned flags will be a string of ascii format flags.\r
118 + *\r
119 + * The returned string belongs to the message so should not be\r
120 + * modified or freed by the caller (nor should it be referenced after\r
121 + * the message is destroyed). */\r
122 +const char *\r
123 +notmuch_message_get_flags (notmuch_message_t *message);\r
124 +\r
125  /* Get the date of 'message' as a time_t value.\r
126   *\r
127   * For the original textual representation of the Date header from the\r
128 -- \r
129 1.6.5.3\r
130 \r