aboutsummaryrefslogtreecommitdiffstats
path: root/mail/e-mail-reader.c
diff options
context:
space:
mode:
Diffstat (limited to 'mail/e-mail-reader.c')
-rw-r--r--mail/e-mail-reader.c154
1 files changed, 3 insertions, 151 deletions
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index dc163bda06..ec667765e2 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -410,159 +410,11 @@ action_mail_remove_attachments_cb (GtkAction *action, EMailReader *reader)
mail_remove_attachments (folder, uids);
}
-static gchar *
-get_message_checksum (CamelFolder *folder, CamelMimeMessage *msg)
-{
- static const GChecksumType duplicate_csum = G_CHECKSUM_SHA256;
-
- CamelDataWrapper *content;
- CamelStream *mem;
- GByteArray *buffer;
- gchar *digest = NULL;
-
- if (!msg)
- return NULL;
-
- /* get message contents */
- content = camel_medium_get_content ((CamelMedium *) msg);
- if (!content)
- return NULL;
-
- /* calculate checksum */
- mem = camel_stream_mem_new ();
- camel_data_wrapper_decode_to_stream_sync (content, mem, NULL, NULL);
-
- buffer = camel_stream_mem_get_byte_array (CAMEL_STREAM_MEM (mem));
- if (buffer)
- digest = g_compute_checksum_for_data (
- duplicate_csum, buffer->data, buffer->len);
-
- g_object_unref (mem);
-
- return digest;
-}
-
-static gboolean
-message_is_duplicated (GHashTable *messages, guint64 id, gchar *digest)
-{
- gchar *hash_digest = g_hash_table_lookup (messages, &id);
-
- if (!hash_digest)
- return FALSE;
-
- return g_str_equal (digest, hash_digest);
-}
-
static void
-remove_duplicates_got_messages_cb (CamelFolder *folder,
- GPtrArray *uids,
- GPtrArray *msgs,
- gpointer data)
-{
- EMailReader *reader = data;
- GtkWindow *parent;
- GHashTable *messages;
- GPtrArray *dups;
- gint ii;
-
- g_return_if_fail (CAMEL_IS_FOLDER (folder));
- g_return_if_fail (uids != NULL);
- g_return_if_fail (msgs != NULL);
- g_return_if_fail (msgs->len <= uids->len);
- g_return_if_fail (E_IS_MAIL_READER (reader));
-
- parent = e_mail_reader_get_window (reader);
-
- messages = g_hash_table_new_full (
- g_int_hash, g_int_equal, g_free, g_free);
- dups = g_ptr_array_new ();
-
- for (ii = 0; ii < msgs->len; ii++) {
- CamelMessageInfo *msg_info;
- const CamelSummaryMessageID *mid;
- guint32 flags;
-
- msg_info = camel_folder_get_message_info (
- folder, uids->pdata[ii]);
- mid = camel_message_info_message_id (msg_info);
- flags = camel_message_info_flags (msg_info);
-
- if (!(flags & CAMEL_MESSAGE_DELETED)) {
- gchar *digest;
-
- digest = get_message_checksum (folder, msgs->pdata[ii]);
-
- if (digest != NULL) {
- if (message_is_duplicated (
- messages, mid->id.id, digest)) {
- g_ptr_array_add (dups, uids->pdata[ii]);
- g_free (digest);
- } else {
- guint64 *id;
-
- id = g_new0 (guint64, 1);
- *id = mid->id.id;
-
- g_hash_table_insert (
- messages, id, digest);
- }
- }
- }
-
- camel_message_info_free (msg_info);
- }
-
- if (dups->len == 0) {
- em_utils_prompt_user (
- parent, NULL, "mail:info-no-remove-duplicates",
- camel_folder_get_display_name (folder), NULL);
- } else {
- gchar *msg = g_strdup_printf (ngettext (
- /* Translators: %s is replaced with a folder name
- %d with count of duplicate messages. */
- "Folder '%s' contains %d duplicate message. "
- "Are you sure you want to delete it?",
- "Folder '%s' contains %d duplicate messages. "
- "Are you sure you want to delete them?",
- dups->len),
- camel_folder_get_display_name (folder), dups->len);
-
- if (em_utils_prompt_user (
- parent, NULL, "mail:ask-remove-duplicates", msg, NULL)) {
- camel_folder_freeze (folder);
- for (ii = 0; ii < dups->len; ii++)
- camel_folder_delete_message (
- folder, g_ptr_array_index (dups, ii));
- camel_folder_thaw (folder);
- }
-
- g_free (msg);
- }
-
- g_hash_table_destroy (messages);
- g_ptr_array_free (dups, TRUE);
-}
-
-static void
-action_mail_remove_duplicates (GtkAction *action, EMailReader *reader)
+action_mail_remove_duplicates (GtkAction *action,
+ EMailReader *reader)
{
- MessageList *message_list;
- CamelFolder *folder;
- GPtrArray *uids;
-
- message_list = MESSAGE_LIST (e_mail_reader_get_message_list (reader));
- uids = message_list_get_selected (message_list);
- folder = message_list->folder;
-
- if (!uids || uids->len <= 1) {
- if (uids)
- em_utils_uids_free (uids);
- } else {
- /* the function itself is freeing uids */
- mail_get_messages (
- folder, uids,
- remove_duplicates_got_messages_cb, reader);
- }
+ e_mail_reader_remove_duplicates (reader);
}
static void