diff options
author | Milan Crha <mcrha@redhat.com> | 2009-10-31 00:01:01 +0800 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2009-10-31 00:01:01 +0800 |
commit | daa8339f17aa54b33b562e1de4faec24a14969b4 (patch) | |
tree | ab2d8b91739e4bd74ae72c17549002a4202af096 | |
parent | eff08fcad7dd0b1cecd9d5d25d997d7b5ea41f84 (diff) | |
download | gsoc2013-evolution-daa8339f17aa54b33b562e1de4faec24a14969b4.tar gsoc2013-evolution-daa8339f17aa54b33b562e1de4faec24a14969b4.tar.gz gsoc2013-evolution-daa8339f17aa54b33b562e1de4faec24a14969b4.tar.bz2 gsoc2013-evolution-daa8339f17aa54b33b562e1de4faec24a14969b4.tar.lz gsoc2013-evolution-daa8339f17aa54b33b562e1de4faec24a14969b4.tar.xz gsoc2013-evolution-daa8339f17aa54b33b562e1de4faec24a14969b4.tar.zst gsoc2013-evolution-daa8339f17aa54b33b562e1de4faec24a14969b4.zip |
Bug #464400 - New mail notify should display sender and subject
-rw-r--r-- | mail/em-event.c | 12 | ||||
-rw-r--r-- | mail/em-event.h | 7 | ||||
-rw-r--r-- | mail/mail-folder-cache.c | 52 | ||||
-rw-r--r-- | plugins/mail-notification/mail-notification.c | 62 |
4 files changed, 113 insertions, 20 deletions
diff --git a/mail/em-event.c b/mail/em-event.c index 4434e0a447..7cb4c19a1e 100644 --- a/mail/em-event.c +++ b/mail/em-event.c @@ -65,7 +65,10 @@ eme_target_free(EEvent *ep, EEventTarget *t) case EM_EVENT_TARGET_FOLDER: { EMEventTargetFolder *s = (EMEventTargetFolder *)t; g_free (s->name); - g_free(s->uri); + g_free (s->uri); + g_free (s->msg_uid); + g_free (s->msg_sender); + g_free (s->msg_subject); break; } case EM_EVENT_TARGET_MESSAGE: { EMEventTargetMessage *s = (EMEventTargetMessage *)t; @@ -136,14 +139,17 @@ EMEvent *em_event_peek(void) } EMEventTargetFolder * -em_event_target_new_folder (EMEvent *eme, const gchar *uri, guint new) +em_event_target_new_folder (EMEvent *eme, const gchar *uri, guint new, const gchar *msg_uid, const gchar *msg_sender, const gchar *msg_subject) { EMEventTargetFolder *t = e_event_target_new(&eme->popup, EM_EVENT_TARGET_FOLDER, sizeof(*t)); guint32 flags = new ? EM_EVENT_FOLDER_NEWMAIL : 0; - t->uri = g_strdup(uri); + t->uri = g_strdup (uri); t->target.mask = ~flags; t->new = new; + t->msg_uid = g_strdup (msg_uid); + t->msg_sender = g_strdup (msg_sender); + t->msg_subject = g_strdup (msg_subject); return t; } diff --git a/mail/em-event.h b/mail/em-event.h index 6f1366ae5f..de58d26bde 100644 --- a/mail/em-event.h +++ b/mail/em-event.h @@ -77,6 +77,11 @@ struct _EMEventTargetFolder { guint new; gboolean is_inbox; gchar *name; + + /* valid (non-NULL) when only one new message reported */ + gchar *msg_uid; + gchar *msg_sender; + gchar *msg_subject; }; typedef struct _EMEventTargetMessage EMEventTargetMessage; @@ -134,7 +139,7 @@ GType em_event_get_type(void); EMEvent *em_event_peek(void); -EMEventTargetFolder *em_event_target_new_folder(EMEvent *emp, const gchar *uri, guint32 flags); +EMEventTargetFolder *em_event_target_new_folder (EMEvent *emp, const gchar *uri, guint32 count_new_msgs, const gchar *msg_uid, const gchar *msg_sender, const gchar *msg_subject); EMEventTargetComposer *em_event_target_new_composer(EMEvent *emp, const EMsgComposer *composer, guint32 flags); EMEventTargetMessage *em_event_target_new_message(EMEvent *emp, CamelFolder *folder, CamelMimeMessage *message, const gchar *uid, guint32 flags, EMsgComposer *composer); diff --git a/mail/mail-folder-cache.c b/mail/mail-folder-cache.c index e9ffc5196e..59f823f81c 100644 --- a/mail/mail-folder-cache.c +++ b/mail/mail-folder-cache.c @@ -101,6 +101,11 @@ struct _folder_update { gint unread; CamelStore *store; + + /* for only one new message... */ + gchar *msg_uid; /* ... its uid ... */ + gchar *msg_sender; /* ... its sender ... */ + gchar *msg_subject; /* ... and its subject. */ }; struct _store_info { @@ -134,13 +139,16 @@ static gint count_trash = FALSE; static void free_update(struct _folder_update *up) { - g_free(up->full_name); - g_free(up->uri); + g_free (up->full_name); + g_free (up->uri); if (up->store) camel_object_unref(up->store); - g_free(up->oldfull); - g_free(up->olduri); - g_free(up); + g_free (up->oldfull); + g_free (up->olduri); + g_free (up->msg_uid); + g_free (up->msg_sender); + g_free (up->msg_subject); + g_free (up); } static void @@ -185,7 +193,7 @@ real_flush_updates (void) if (up->uri) { EMEvent *e = em_event_peek(); - EMEventTargetFolder *t = em_event_target_new_folder(e, up->uri, up->new); + EMEventTargetFolder *t = em_event_target_new_folder(e, up->uri, up->new, up->msg_uid, up->msg_sender, up->msg_subject); t->is_inbox = em_folder_tree_model_is_type_inbox ( default_model, up->store, up->full_name); @@ -300,7 +308,7 @@ free_folder_info(struct _folder_info *mfi) * it's correct. */ static void -update_1folder(struct _folder_info *mfi, gint new, CamelFolderInfo *info) +update_1folder(struct _folder_info *mfi, gint new, const gchar *msg_uid, const gchar *msg_sender, const gchar *msg_subject, CamelFolderInfo *info) { struct _folder_update *up; CamelFolder *folder; @@ -350,6 +358,9 @@ update_1folder(struct _folder_info *mfi, gint new, CamelFolderInfo *info) up->new = new; up->store = mfi->store_info->store; up->uri = g_strdup(mfi->uri); + up->msg_uid = g_strdup (msg_uid); + up->msg_sender = g_strdup (msg_sender); + up->msg_subject = g_strdup (msg_subject); camel_object_ref(up->store); g_queue_push_head (&updates, up); flush_updates(); @@ -363,7 +374,7 @@ setup_folder(CamelFolderInfo *fi, struct _store_info *si) mfi = g_hash_table_lookup(si->folders, fi->full_name); if (mfi) { - update_1folder(mfi, 0, fi); + update_1folder (mfi, 0, NULL, NULL, NULL, fi); } else { d(printf("Adding new folder: %s (%s)\n", fi->full_name, fi->uri)); mfi = g_malloc0(sizeof(*mfi)); @@ -421,6 +432,7 @@ folder_changed (CamelObject *o, gpointer event_data, gpointer user_data) gint new = 0; gint i; guint32 flags; + gchar *uid = NULL, *sender = NULL, *subject = NULL; d(printf("folder '%s' changed\n", folder->full_name)); @@ -442,8 +454,22 @@ folder_changed (CamelObject *o, gpointer event_data, gpointer user_data) if (((flags & CAMEL_MESSAGE_SEEN) == 0) && ((flags & CAMEL_MESSAGE_JUNK) == 0) && ((flags & CAMEL_MESSAGE_DELETED) == 0) && - (camel_message_info_date_received (info) > last_newmail)) + (camel_message_info_date_received (info) > last_newmail)) { new++; + if (new == 1) { + uid = g_strdup (camel_message_info_uid (info)); + sender = g_strdup (camel_message_info_from (info)); + subject = g_strdup (camel_message_info_subject (info)); + } else { + g_free (uid); + g_free (sender); + g_free (subject); + + uid = NULL; + sender = NULL; + subject = NULL; + } + } camel_message_info_free (info); } } @@ -457,9 +483,13 @@ folder_changed (CamelObject *o, gpointer event_data, gpointer user_data) && (si = g_hash_table_lookup(stores, store)) != NULL && (mfi = g_hash_table_lookup(si->folders, folder->full_name)) != NULL && mfi->folder == folder) { - update_1folder(mfi, new, NULL); + update_1folder (mfi, new, uid, sender, subject, NULL); } G_UNLOCK (stores); + + g_free (uid); + g_free (sender); + g_free (subject); } static void @@ -519,7 +549,7 @@ void mail_note_folder(CamelFolder *folder) mfi->folder = folder; - update_1folder(mfi, 0, NULL); + update_1folder (mfi, 0, NULL, NULL, NULL, NULL); G_UNLOCK (stores); diff --git a/plugins/mail-notification/mail-notification.c b/plugins/mail-notification/mail-notification.c index b884b0272b..ab4fcda689 100644 --- a/plugins/mail-notification/mail-notification.c +++ b/plugins/mail-notification/mail-notification.c @@ -116,7 +116,7 @@ static DBusConnection *bus = NULL; static gboolean init_dbus (void); static void -send_dbus_message (const gchar *name, const gchar *data, guint new) +send_dbus_message (const gchar *name, const gchar *data, guint new, const gchar *msg_uid, const gchar *msg_sender, const gchar *msg_subject) { DBusMessage *message; @@ -134,6 +134,19 @@ send_dbus_message (const gchar *name, const gchar *data, guint new) DBUS_TYPE_INVALID); } + #define add_named_param(name, value) \ + if (value) { \ + gchar *val; \ + val = g_strconcat (name, ":", value, NULL); \ + dbus_message_append_args (message, DBUS_TYPE_STRING, &val, DBUS_TYPE_INVALID); \ + } + + add_named_param ("msg_uid", msg_uid); + add_named_param ("msg_sender", msg_sender); + add_named_param ("msg_subject", msg_subject); + + #undef add_named_param + /* Sends the message */ dbus_connection_send (bus, message, NULL); @@ -196,14 +209,14 @@ static void new_notify_dbus (EMEventTargetFolder *t) { if (bus != NULL) - send_dbus_message ("Newmail", t->uri, t->new); + send_dbus_message ("Newmail", t->uri, t->new, t->msg_uid, t->msg_sender, t->msg_subject); } static void read_notify_dbus (EMEventTargetMessage *t) { if (bus != NULL) - send_dbus_message ("MessageReading", t->folder->name, 0); + send_dbus_message ("MessageReading", t->folder->name, 0, NULL, NULL, NULL); } static void @@ -462,11 +475,50 @@ new_notify_status (EMEventTargetFolder *t) g_strdup (t->uri), (GDestroyNotify) g_free); if (!status_count) { + EAccount *account; + gchar *name = t->name; + + account = mail_config_get_account_by_source_url (t->uri); + + if (account != NULL) { + name = g_strdup_printf ( + "%s/%s", e_account_get_string ( + account, E_ACCOUNT_NAME), name); + } + status_count = t->new; - /* To translators: '%d' is the number of mails recieved and '%s' is the name of the folder*/ + + /* To translators: '%d' is the count of mails received and '%s' is the name of the folder*/ msg = g_strdup_printf (ngettext ("You have received %d new message\nin %s.", "You have received %d new messages\nin %s.", - status_count),status_count, t->name); + status_count), status_count, name); + + if (name != t->name) + g_free (name); + + if (t->msg_sender) { + gchar *tmp, *str; + + /* To Translators: "From:" is preceding a new mail sender address, like "From: user@example.com" */ + str = g_strdup_printf (_("From: %s"), t->msg_sender); + tmp = g_strconcat (msg, "\n", str, NULL); + + g_free (msg); + g_free (str); + msg = tmp; + } + + if (t->msg_subject) { + gchar *tmp, *str; + + /* To Translators: "Subject:" is preceding a new mail subject, like "Subject: It happened again" */ + str = g_strdup_printf (_("Subject: %s"), t->msg_subject); + tmp = g_strconcat (msg, "\n", str, NULL); + + g_free (msg); + g_free (str); + msg = tmp; + } } else { status_count += t->new; msg = g_strdup_printf (ngettext ("You have received %d new message.", |