src/mn-evolution-message.gob (3770B) - 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-message.h" 22 %} 23 24 %{ 25 #include <glib/gi18n.h> 26 #include <camel/camel-folder-summary.h> 27 #include "mn-evolution-mailbox.h" 28 #include "mn-message-private.h" 29 #include "mn-evolution-client.h" 30 #include "mn-evolution-client-dbus.h" 31 #include "mn-util.h" 32 33 #define CLIENT_METHOD(invocation) \ 34 { \ 35 MNEvolutionMailbox *mailbox = MN_EVOLUTION_MAILBOX(message->mailbox); \ 36 MNEvolutionClient *client; \ 37 GError *tmp_err = NULL; \ 38 GError *err = NULL; \ 39 \ 40 client = mn_evolution_client_get(); \ 41 \ 42 if (! client->proxy) \ 43 { \ 44 g_set_error(&err, 0, 0, _("Unable to contact Evolution.")); \ 45 goto end; \ 46 } \ 47 \ 48 if (! invocation) \ 49 { \ 50 g_set_error(&err, 0, 0, _("An Evolution error has occurred: %s."), tmp_err->message); \ 51 g_error_free(tmp_err); \ 52 } \ 53 \ 54 end: \ 55 mn_message_action_done(request, err); \ 56 } 57 %} 58 59 class MN:Evolution:Message from MN:Message 60 { 61 private char *uid destroywith g_free; 62 property STRING uid (link, flags = CONSTRUCT_ONLY | MN_MESSAGE_PARAM_EXPORT); 63 64 public MNMessage * 65 new (MNMailbox *mailbox, 66 time_t sent_time, 67 const char *id, 68 const char *from, 69 const char *subject, 70 MNMessageFlags flags, 71 const char *uid (check null)) 72 { 73 return MN_MESSAGE(GET_NEW_VARG(MN_MESSAGE_PROP_MAILBOX(mailbox), 74 MN_MESSAGE_PROP_SENT_TIME(sent_time), 75 MN_MESSAGE_PROP_ID((char *) id), 76 MN_MESSAGE_PROP_FROM((char *) from), 77 MN_MESSAGE_PROP_SUBJECT((char *) subject), 78 MN_MESSAGE_PROP_FLAGS(flags), 79 MN_EVOLUTION_MESSAGE_PROP_UID((char *) uid), 80 NULL)); 81 } 82 83 override (MN:Message) gboolean 84 builtin_can_open (MNMessage *message) 85 { 86 return TRUE; 87 } 88 89 override (MN:Message) void 90 builtin_open (MNMessage *message, MNMessageActionRequest *request) 91 { 92 Self *self = SELF(message); 93 CLIENT_METHOD(org_gnome_MailNotification_Evolution_open_message(client->proxy, mailbox->uri, selfp->uid, &tmp_err)); 94 } 95 96 private void 97 set_flags (self, guint32 flags, MNMessageActionRequest *request) 98 { 99 MNMessage *message = MN_MESSAGE(self); 100 CLIENT_METHOD(org_gnome_MailNotification_Evolution_set_message_flags(client->proxy, mailbox->uri, selfp->uid, flags, &tmp_err)); 101 } 102 103 override (MN:Message) void 104 builtin_mark_as_read (MNMessage *message, MNMessageActionRequest *request) 105 { 106 self_set_flags(SELF(message), CAMEL_MESSAGE_SEEN, request); 107 } 108 109 override (MN:Message) void 110 builtin_mark_as_spam (MNMessage *message, MNMessageActionRequest *request) 111 { 112 self_set_flags(SELF(message), CAMEL_MESSAGE_SEEN | CAMEL_MESSAGE_JUNK | CAMEL_MESSAGE_JUNK_LEARN, request); 113 } 114 115 override (MN:Message) void 116 builtin_delete (MNMessage *message, MNMessageActionRequest *request) 117 { 118 self_set_flags(SELF(message), CAMEL_MESSAGE_SEEN | CAMEL_MESSAGE_DELETED, request); 119 } 120 }