src/mn-mozilla-mailbox-backend.gob (2413B) - raw
1 /*
2 * Mail Notification
3 * Copyright (C) 2003-2008 Jean-Yves Lefort <jylefort@brutele.be>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 %headertop{
21 #include "mn-base-mbox-mailbox-backend.h"
22 %}
23
24 %{
25 #include <stdlib.h>
26 #include <limits.h>
27 #include "mn-base-mbox-mailbox-backend-private.h"
28 #include "mn-message-mime.h"
29 #include "mn-util.h"
30
31 /* taken from base/public/nsMsgMessageFlags.h in the Mozilla Mail&News sources */
32 /* in X-Mozilla-Status */
33 #define MOZILLA_MSG_FLAG_READ 0x0001
34 #define MOZILLA_MSG_FLAG_EXPUNGED 0x0008
35 /* in X-Mozilla-Status2 */
36 #define MOZILLA_MSG_FLAG_NEW 0x10000
37 %}
38
39 class MN:Mozilla:Mailbox:Backend from MN:Base:Mbox:Mailbox:Backend
40 {
41 class_init (class)
42 {
43 MN_VFS_MAILBOX_BACKEND_CLASS(class)->format = "Mozilla";
44 }
45
46 override (MN:Base:Mbox:Mailbox:Backend) MNMessage *
47 get_new_message (MNBaseMboxMailboxBackend *backend, GMimeMessage *mime_message)
48 {
49 int flags;
50
51 flags = self_get_status_flags(mime_message, "X-Mozilla-Status");
52 if ((flags & MOZILLA_MSG_FLAG_READ) == 0
53 && (flags & MOZILLA_MSG_FLAG_EXPUNGED) == 0)
54 {
55 int mn_flags = 0;
56
57 if ((self_get_status_flags(mime_message, "X-Mozilla-Status2") & MOZILLA_MSG_FLAG_NEW) != 0)
58 mn_flags |= MN_MESSAGE_NEW;
59
60 return mn_message_new_from_mime_message(MN_MAILBOX(MN_VFS_MAILBOX_BACKEND(backend)->mailbox), mime_message, NULL, mn_flags, FALSE);
61 }
62 else
63 return NULL;
64 }
65
66 private int
67 get_status_flags (GMime:Message *mime_message (check null type),
68 const char *header_name (check null))
69 {
70 const char *header;
71
72 header = g_mime_message_get_header(mime_message, header_name);
73 if (header && mn_str_ishex(header))
74 return strtol(header, NULL, 16);
75 else
76 return 0;
77 }
78 }