+ priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
+
+ info = g_slice_new0 (SendMsgInfo);
+
+ info->mail_op = g_object_ref (self);
+ info->msg = g_object_ref (msg);
+ info->msg_sent_handler = g_signal_connect (G_OBJECT (send_queue), "msg-sent",
+ G_CALLBACK (send_mail_msg_sent_handler), info);
+ info->error_happened_handler = g_signal_connect (G_OBJECT (send_queue), "error-happened",
+ G_CALLBACK (send_mail_error_happened_handler), info);
+ }
+
+}
+
+static void
+common_send_mail_operation_end (TnySendQueue *queue, TnyMsg *msg,
+ SendMsgInfo *info)
+{
+ g_signal_handler_disconnect (queue, info->msg_sent_handler);
+ g_signal_handler_disconnect (queue, info->error_happened_handler);
+
+ g_object_unref (info->msg);
+ modest_mail_operation_notify_end (info->mail_op);
+ g_object_unref (info->mail_op);
+
+ g_slice_free (SendMsgInfo, info);
+}
+
+static void
+send_mail_msg_sent_handler (TnySendQueue *queue, TnyHeader *header, TnyMsg *msg,
+ guint nth, guint total, gpointer userdata)
+{
+ SendMsgInfo *info = (SendMsgInfo *) userdata;
+ TnyHeader *hdr1, *hdr2;
+ const char *msgid1, *msgid2;
+ hdr1 = tny_msg_get_header(msg);
+ hdr2 = tny_msg_get_header(info->msg);
+ msgid1 = tny_header_get_message_id(hdr1);
+ msgid2 = tny_header_get_message_id(hdr2);
+ if (msgid1 == NULL) msgid1 = "(null)";
+ if (msgid2 == NULL) msgid2 = "(null)";
+
+ if (!strcmp (msgid1, msgid2)) {
+ ModestMailOperationPrivate *priv = MODEST_MAIL_OPERATION_GET_PRIVATE (info->mail_op);