+
+/* get the new To:, based on the old header,
+ * result is newly allocated or NULL in case of error
+ * TODO: mailing list handling
+ * */
+static gchar*
+get_new_to (TnyHeader *header, const gchar* from, ModestTnyMsgReplyMode mode)
+{
+ const gchar* old_to;
+ const gchar* old_reply_to_from;
+
+ gchar* new_to;
+
+ /* reply to sender, use ReplyTo or From */
+ old_reply_to_from = tny_header_get_replyto (header);
+ if (old_reply_to_from)
+ new_to = g_strdup (old_reply_to_from);
+ else {
+ old_reply_to_from = tny_header_get_from (header);
+ if (old_reply_to_from)
+ new_to = g_strdup (old_reply_to_from);
+ else {
+ g_warning ("%s: failed to get either Reply-To: or From: from header",
+ __FUNCTION__);
+ return NULL;
+ }
+ }
+
+ /* in case of ReplyAll, we need to add the Recipients in the old To: */
+ if (mode == MODEST_TNY_MSG_REPLY_MODE_ALL) {
+ old_to = tny_header_get_to (header);
+ if (!old_to)
+ g_warning ("%s: no To: address found in source mail", __FUNCTION__);
+ else {
+ /* append the old To: */
+ gchar *tmp = g_strjoin (",", new_to, old_to, NULL);
+ g_free (new_to);
+ new_to = tmp;
+ }
+ }
+
+ /* now, strip me (the new From:) from the new_to */
+ gchar *tmp = modest_text_utils_remove_address (new_to, from);
+ g_free (new_to);
+ new_to = tmp;
+
+ return new_to;
+}
+
+
+/* get the new Cc:, based on the old header,
+ * result is newly allocated or NULL in case of error */
+static gchar*
+get_new_cc (TnyHeader *header, const gchar* from, ModestTnyMsgReplyMode mode)
+{
+ const gchar *old_cc;
+
+ old_cc = tny_header_get_cc (header);
+ if (!old_cc)
+ return NULL;
+
+ /* remove me (the new From:) from the Cc: list */
+ return modest_text_utils_remove_address (old_cc, from);
+}
+
+