/*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2013 Hiroyuki Yamamoto and the Claws Mail team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2016 Hiroyuki Yamamoto and the Claws Mail team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
*/
#include "defs.h"
#include "version.h"
#include "statusbar.h"
#include "folder_item_prefs.h"
-#ifndef USE_NEW_ADDRBOOK
+#include "avatars.h"
+#ifndef USE_ALT_ADDRBOOK
#include "addressbook.h"
#else
#include "addressadd.h"
{"View/Goto/ParentMessage", NULL, N_("Parent message"), "<control>Up", NULL, G_CALLBACK(parent_cb) },
/* {"View/Goto/---", NULL, "---", NULL, NULL, NULL }, */
{"View/Goto/NextUnreadFolder", NULL, N_("Next unread _folder"), "<shift>G", NULL, G_CALLBACK(goto_unread_folder_cb) },
- {"View/Goto/OtherFolder", NULL, N_("_Other folder..."), "G", NULL, G_CALLBACK(goto_folder_cb) },
+ {"View/Goto/Folder", NULL, N_("F_older..."), "G", NULL, G_CALLBACK(goto_folder_cb) },
/* {"View/Goto/---", NULL, "---", NULL, NULL, NULL }, */
{"View/Goto/NextPart", NULL, N_("Next part"), "A", NULL, G_CALLBACK(goto_next_part_cb) },
{"View/Goto/PrevPart", NULL, N_("Previous part"), "Z", NULL, G_CALLBACK(goto_prev_part_cb) },
ENC_ACTION(CS_ISO_8859_9, C_ISO_8859_9, N_("Turkish (ISO-8859-_9)")), /* RADIO set_charset_cb */
ENC_ACTION("Cyrillic/"CS_ISO_8859_5, C_ISO_8859_5, "ISO-8859-_5"), /* RADIO set_charset_cb */
ENC_ACTION("Cyrillic/"CS_KOI8_R, C_KOI8_R, "KOI8-_R"), /* RADIO set_charset_cb */
+ ENC_ACTION("Cyrillic/"CS_MACCYR, C_MACCYR, "MAC_CYR"), /* RADIO set_charset_cb */
ENC_ACTION("Cyrillic/"CS_KOI8_U, C_KOI8_U, "KOI8-_U"), /* RADIO set_charset_cb */
ENC_ACTION("Cyrillic/"CS_WINDOWS_1251, C_WINDOWS_1251, "Windows-1251"), /* RADIO set_charset_cb */
ENC_ACTION("Japanese/"CS_ISO_2022_JP, C_ISO_2022_JP, "ISO-2022-_JP"), /* RADIO set_charset_cb */
return messageview;
}
-GList *messageview_get_msgview_list(void)
+const GList *messageview_get_msgview_list(void)
{
return msgview_list;
}
MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "ParentMessage", "View/Goto/ParentMessage", GTK_UI_MANAGER_MENUITEM)
MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator7", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "NextUnreadFolder", "View/Goto/NextUnreadFolder", GTK_UI_MANAGER_MENUITEM)
- MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "OtherFolder", "View/Goto/OtherFolder", GTK_UI_MANAGER_MENUITEM)
+ MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Folder", "View/Goto/Folder", GTK_UI_MANAGER_MENUITEM)
MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator8", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "NextPart", "View/Goto/NextPart", GTK_UI_MANAGER_MENUITEM)
MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "PrevPart", "View/Goto/PrevPart", GTK_UI_MANAGER_MENUITEM)
MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Cyrillic", "View/Encoding/Cyrillic", GTK_UI_MANAGER_MENU)
MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_ISO_8859_5, "View/Encoding/Cyrillic/"CS_ISO_8859_5, GTK_UI_MANAGER_MENUITEM)
MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_KOI8_R, "View/Encoding/Cyrillic/"CS_KOI8_R, GTK_UI_MANAGER_MENUITEM)
+ MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_MACCYR, "View/Encoding/Cyrillic/"CS_MACCYR, GTK_UI_MANAGER_MENUITEM)
MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_KOI8_U, "View/Encoding/Cyrillic/"CS_KOI8_U, GTK_UI_MANAGER_MENUITEM)
MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_WINDOWS_1251, "View/Encoding/Cyrillic/"CS_WINDOWS_1251, GTK_UI_MANAGER_MENUITEM)
ok = strcasecmp(to_addr, buf);
g_free(to_addr);
} else {
- strncpy(buf, _("<No Return-Path found>"),
+ g_strlcpy(buf, _("<No Return-Path found>"),
sizeof(buf));
}
/* chmod for security */
if (change_file_mode_rw(fp, tmp) < 0) {
FILE_OP_ERROR(tmp, "chmod");
- g_warning("can't change file mode\n");
+ g_warning("can't change file mode");
}
addr = g_strdup(to);
queue = account_get_special_folder(account, F_QUEUE);
if (!queue) queue = folder_get_default_queue();
if (!queue) {
- g_warning("can't find queue folder\n");
+ g_warning("can't find queue folder");
claws_unlink(tmp);
return -1;
}
folder_item_scan(queue);
if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
- g_warning("can't queue the message\n");
+ g_warning("can't queue the message");
claws_unlink(tmp);
return -1;
}
}
gboolean messageview_nav_has_prev(MessageView *messageview) {
- return messageview->trail != NULL && messageview->trail_pos > 0;
+ return messageview != NULL && messageview->trail != NULL
+ && messageview->trail_pos > 0;
}
gboolean messageview_nav_has_next(MessageView *messageview) {
- if (!messageview->trail)
+ if (!messageview || !messageview->trail)
return FALSE;
return sc_g_list_bigger(messageview->trail, messageview->trail_pos + 1);
return info;
}
+static gboolean messageview_try_select_mimeinfo(MessageView *messageview, MsgInfo *msginfo, MimeInfo *mimeinfo)
+{
+ if (mimeinfo->type == MIMETYPE_TEXT) {
+ if (!strcasecmp(mimeinfo->subtype, "calendar")
+ && mimeview_has_viewer_for_content_type(messageview->mimeview, "text/calendar")) {
+ mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
+ return TRUE;
+ } else if (!strcasecmp(mimeinfo->subtype, "html")
+ && mimeinfo->disposition != DISPOSITIONTYPE_ATTACHMENT
+ && (msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_ALWAYS
+ || (msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_DEFAULT
+ && prefs_common.promote_html_part))) {
+ mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+static void messageview_find_part_depth_first(MimeInfoSearch *context, MimeMediaType type, const gchar *subtype)
+{
+ MimeInfo * mimeinfo = context->current;
+
+ if (!mimeinfo)
+ return;
+
+ debug_print("found part %d/%s\n", mimeinfo->type, mimeinfo->subtype);
+
+ if (mimeinfo->type == type
+ && !strcasecmp(mimeinfo->subtype, subtype)) {
+ context->found = mimeinfo;
+ } else if (mimeinfo->type == MIMETYPE_MULTIPART) {
+ if (!strcasecmp(mimeinfo->subtype, "alternative")
+ || !strcasecmp(mimeinfo->subtype, "related")) {
+ context->found = procmime_mimeinfo_next(mimeinfo);
+ while (context->found && context->found != context->parent) {
+ if (context->found->type == type
+ && !strcasecmp(context->found->subtype, subtype))
+ break;
+ context->found = procmime_mimeinfo_next(context->found);
+ }
+ if (context->found == context->parent)
+ context->found = NULL;
+ }
+ if (!context->found
+ && (!strcasecmp(mimeinfo->subtype, "related")
+ || !strcasecmp(mimeinfo->subtype, "mixed"))) {
+ context->parent = mimeinfo;
+ context->current = procmime_mimeinfo_next(mimeinfo);
+ messageview_find_part_depth_first(context, type, subtype);
+ }
+ }
+}
+
gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
gboolean all_headers)
{
gchar *text = NULL;
gchar *file;
- MimeInfo *mimeinfo, *encinfo, *brokeninfo, *root;
+ MimeInfo *mimeinfo, *encinfo, *root;
gchar *subject = NULL;
cm_return_val_if_fail(msginfo != NULL, -1);
statuswindow_pop_all();
if (!file) {
- g_warning("can't get message file path.\n");
+ g_warning("can't get message file path.");
textview_show_error(messageview->mimeview->textview);
return -1;
}
}
if (messageview->msginfo != msginfo) {
- procmsg_msginfo_free(messageview->msginfo);
+ procmsg_msginfo_free(&(messageview->msginfo));
messageview->msginfo = NULL;
messageview_set_menu_sensitive(messageview);
messageview->msginfo =
messageview_set_menu_sensitive(messageview);
messageview->msginfo = msginfo;
}
- headerview_show(messageview->headerview, messageview->msginfo);
+ if (prefs_common.display_header_pane)
+ headerview_show(messageview->headerview, messageview->msginfo);
messageview_register_nav(messageview);
messageview_set_position(messageview, 0);
return_receipt_show(messageview->noticeview,
messageview->msginfo);
- if ((brokeninfo = find_broken_part(mimeinfo)) != NULL) {
+ if (find_broken_part(mimeinfo) != NULL) {
noticeview_set_icon(messageview->noticeview,
STOCK_PIXMAP_NOTICE_WARN);
if (!noticeview_is_visible(messageview->noticeview)) {
root = mimeinfo;
mimeinfo = procmime_mimeinfo_next(mimeinfo);
- if (!all_headers && mimeinfo
- && (mimeinfo->type != MIMETYPE_TEXT ||
- strcasecmp(mimeinfo->subtype, "plain"))
- && (mimeinfo->type != MIMETYPE_MULTIPART ||
- strcasecmp(mimeinfo->subtype, "signed"))) {
- if (strcasecmp(mimeinfo->subtype, "html")) {
- MimeInfo *saved_mimeinfo = mimeinfo;
- MimeInfo *alt_parent = mimeinfo;
-
- /* if multipart/{related,mixed} part, look inside for a multipart/alternative child */
- if (mimeinfo->type == MIMETYPE_MULTIPART &&
- (!strcasecmp(mimeinfo->subtype, "related") ||
- !strcasecmp(mimeinfo->subtype, "mixed"))) {
- for (; mimeinfo; mimeinfo = procmime_mimeinfo_next(mimeinfo)) {
- if (mimeinfo->node->parent != saved_mimeinfo->node) {
- /* only consider children of the
- * multipart/{related,mixed} part */
- continue;
- }
- if (mimeinfo->type == MIMETYPE_MULTIPART &&
- !strcasecmp(mimeinfo->subtype, "alternative")) {
- /* we got an alternative part */
- alt_parent = mimeinfo;
- break;
- }
- if (mimeinfo->type == MIMETYPE_TEXT &&
- !strcasecmp(mimeinfo->subtype, "calendar") &&
- mimeview_has_viewer_for_content_type(messageview->mimeview,
- "text/calendar")) {
- mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
- goto done;
- } else if (mimeinfo->type == MIMETYPE_TEXT &&
- !strcasecmp(mimeinfo->subtype, "html") &&
- mimeinfo->disposition != DISPOSITIONTYPE_ATTACHMENT &&
- (msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_ALWAYS ||
- (msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_DEFAULT &&
- prefs_common.promote_html_part))) {
- mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
- goto done;
- }
- }
- }
-
- /* if we now have a multipart/alternative part (possibly inside a
- * multipart/{related,mixed} part, look for an HTML part inside */
- if (mimeinfo && mimeinfo->type == MIMETYPE_MULTIPART &&
- !strcasecmp(mimeinfo->subtype, "alternative")) {
- for (; mimeinfo; mimeinfo = procmime_mimeinfo_next(mimeinfo)) {
- if (mimeinfo->node->parent != alt_parent->node) {
- /* only consider children of the
- * multipart/alternative part, so as
- * not to show html attachments */
- continue;
- }
-
- if (mimeinfo->type == MIMETYPE_TEXT &&
- !strcasecmp(mimeinfo->subtype, "calendar") &&
- mimeview_has_viewer_for_content_type(messageview->mimeview,
- "text/calendar")) {
- mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
+ if (!all_headers && mimeinfo
+ && (mimeinfo->type != MIMETYPE_TEXT
+ || strcasecmp(mimeinfo->subtype, "plain"))
+ && (mimeinfo->type != MIMETYPE_MULTIPART
+ || strcasecmp(mimeinfo->subtype, "signed"))) {
+ if (strcasecmp(mimeinfo->subtype, "html")) {
+ MimeInfoSearch context = {
+ .parent = root,
+ .current = mimeinfo,
+ .found = NULL
+ };
+ if (mimeview_has_viewer_for_content_type(messageview->mimeview, "text/calendar")) {
+ MimeInfoSearch cal_context = context;
+ messageview_find_part_depth_first(&cal_context, MIMETYPE_TEXT, "calendar");
+ if (cal_context.found) { /* calendar found */
+ mimeinfo = cal_context.found;
+ if (messageview_try_select_mimeinfo(messageview, msginfo, mimeinfo))
goto done;
- } else if (mimeinfo->type == MIMETYPE_TEXT &&
- !strcasecmp(mimeinfo->subtype, "html") &&
- mimeinfo->disposition != DISPOSITIONTYPE_ATTACHMENT &&
- (msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_ALWAYS ||
- (msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_DEFAULT &&
- prefs_common.promote_html_part))) {
- mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
- goto done;
- }
}
}
-
- /* if we didn't find anything, go back to start */
- if (!mimeinfo)
- mimeinfo = saved_mimeinfo;
+ messageview_find_part_depth_first(&context, MIMETYPE_TEXT, "html");
+ if (context.found &&
+ (msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_ALWAYS ||
+ (msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_DEFAULT &&
+ prefs_common.promote_html_part))) { /* html found */
+ mimeinfo = context.found;
+ if (messageview_try_select_mimeinfo(messageview, msginfo, mimeinfo))
+ goto done;
+ } else
+ mimeinfo = root; /* nothing found */
if (!mimeview_show_part(messageview->mimeview, mimeinfo))
mimeview_select_mimepart_icon(messageview->mimeview, root);
{
if (!messageview)
return;
- procmsg_msginfo_free(messageview->msginfo);
+ procmsg_msginfo_free(&(messageview->msginfo));
messageview->msginfo = NULL;
messageview->filtered = FALSE;
mimeview_destroy(messageview->mimeview);
noticeview_destroy(messageview->noticeview);
- procmsg_msginfo_free(messageview->msginfo);
+ procmsg_msginfo_free(&(messageview->msginfo));
toolbar_clear_list(TOOLBAR_MSGVIEW);
if (messageview->toolbar) {
toolbar_destroy(messageview->toolbar);
if (from_me) {
noticeview_set_icon(noticeview, STOCK_PIXMAP_NOTICE_WARN);
if (MSG_IS_RETRCPT_GOT(msginfo->flags)) {
- noticeview_set_text(noticeview, _("You got a return receipt for this message : "
+ noticeview_set_text(noticeview, _("You got a return receipt for this message: "
"it has been displayed by the recipient."));
} else {
noticeview_set_text(noticeview, _("You asked for a return receipt in this message."));
file = procmsg_get_message_file_path(msginfo);
if (!file) {
- g_warning("can't get message file path.\n");
+ g_warning("can't get message file path.");
return;
}
noticeview_hide(noticeview);
}
- procmsg_msginfo_free(tmpmsginfo);
+ procmsg_msginfo_free(&tmpmsginfo);
g_free(file);
}
GtkTextView *edit = NULL;
GtkTextBuffer *textbuf;
gint body_pos = 0;
+ GtkTextIter start_iter, end_iter;
+ GtkTextMark *body_start, *body_end;
cm_return_val_if_fail(msgview != NULL, NULL);
textbuf = gtk_text_view_get_buffer(edit);
- if (gtk_text_buffer_get_selection_bounds(textbuf, NULL, NULL))
+ if (gtk_text_buffer_get_selection_bounds(textbuf, NULL, NULL)) {
return gtkut_text_view_get_selection(edit);
- else if (msgview->filtered) {
- GtkTextIter start_iter, end_iter;
- gtk_text_buffer_get_iter_at_offset(textbuf, &start_iter, body_pos);
- gtk_text_buffer_get_end_iter(textbuf, &end_iter);
- gtk_text_buffer_get_text(textbuf, &start_iter, &end_iter, FALSE);
- } else
- text = NULL;
+ } else {
+ if (msgview->filtered) {
+ gtk_text_buffer_get_iter_at_offset(textbuf, &start_iter, body_pos);
+ gtk_text_buffer_get_end_iter(textbuf, &end_iter);
+ } else {
+ body_start = gtk_text_buffer_get_mark(textbuf, "body_start");
+
+ /* If there is no body_start mark, an attachment is likely
+ * selected, and we're looking at instructions on what to do
+ * with it. No point in quoting that, so we'll just return NULL,
+ * so that original message body is quoted instead down the line.
+ */
+ if (body_start == NULL) {
+ return NULL;
+ }
+
+ gtk_text_buffer_get_iter_at_mark(textbuf, &start_iter, body_start);
+
+ body_end = gtk_text_buffer_get_mark(textbuf, "body_end");
+ if (body_end != NULL) /* Just in case */
+ gtk_text_buffer_get_iter_at_mark(textbuf, &end_iter, body_end);
+ else
+ gtk_text_buffer_get_end_iter(textbuf, &end_iter);
+ }
+
+ return gtk_text_buffer_get_text(textbuf, &start_iter, &end_iter, FALSE);
+ }
return text;
}
mainwin = mainwindow_get_mainwindow();
printing_print(GTK_TEXT_VIEW(mimeview->textview->text),
mainwin ? GTK_WINDOW(mainwin->window) : NULL,
- sel_start, sel_end);
+ sel_start, sel_end,
+ (mimeview->textview->image
+ ? GTK_IMAGE(mimeview->textview->image)
+ : NULL));
}
}
messageview_show(messageview, info,
messageview->all_headers);
messageview->updating = FALSE;
- procmsg_msginfo_free(info);
+ procmsg_msginfo_free(&info);
if (messageview->deferred_destroy) {
debug_print("messageview got away!\n");
messageview_destroy(messageview);
messageview_show(messageview, info,
messageview->all_headers);
messageview->updating = FALSE;
- procmsg_msginfo_free(info);
+ procmsg_msginfo_free(&info);
if (messageview->deferred_destroy) {
debug_print("messageview got away!\n");
messageview_destroy(messageview);
static void goto_unread_folder_cb(GtkAction *action, gpointer data)
{
MessageView *messageview = (MessageView *)data;
+
messageview->updating = TRUE;
- folderview_select_next_unread(messageview->mainwin->folderview, FALSE);
+ folderview_select_next_with_flag(messageview->mainwin->folderview, MSG_UNREAD, FALSE);
messageview->updating = FALSE;
if (messageview->deferred_destroy) {
if (!msginfo) return;
messageview->msginfo = NULL;
messageview_show(messageview, msginfo, messageview->all_headers);
- procmsg_msginfo_free(msginfo);
+ procmsg_msginfo_free(&msginfo);
main_window_set_menu_sensitive(messageview->mainwin);
summary_redisplay_msg(messageview->mainwin->summaryview);
}
messageview->msginfo = NULL;
messageview_show(messageview, msginfo,
messageview->all_headers);
- procmsg_msginfo_free(msginfo);
+ procmsg_msginfo_free(&msginfo);
/* update main window */
main_window_set_menu_sensitive(messageview->mainwin);
static void addressbook_open_cb(GtkAction *action, gpointer data)
{
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
addressbook_open(NULL);
#else
GError* error = NULL;
addressbook_dbus_open(FALSE, &error);
if (error) {
- g_warning("Failed to open address book");
- g_warning("%s", error->message);
+ g_warning("Failed to open address book: %s", error->message);
g_error_free(error);
}
#endif
MessageView *messageview = (MessageView *)data;
MsgInfo *msginfo, *full_msginfo;
gchar *from;
- GtkWidget *image = NULL;
GdkPixbuf *picture = NULL;
+ AvatarRender *avatarr;
if (!messageview->msginfo || !messageview->msginfo->from)
return;
extract_address(from);
full_msginfo = procmsg_msginfo_get_full_info(msginfo);
- if (full_msginfo &&
- full_msginfo->extradata &&
- full_msginfo->extradata->face) {
- image = face_get_from_header(full_msginfo->extradata->face);
- }
-#if HAVE_LIBCOMPFACE
- else if (full_msginfo &&
- full_msginfo->extradata &&
- full_msginfo->extradata->xface) {
- image = xface_get_from_header(full_msginfo->extradata->xface,
- &(gtk_widget_get_style(messageview->mainwin->summaryview->ctree)->white),
- gtk_widget_get_window(messageview->window));
- }
-#endif
- procmsg_msginfo_free(full_msginfo);
- if (image)
- picture = gtk_image_get_pixbuf(GTK_IMAGE(image));
-#ifndef USE_NEW_ADDRBOOK
+ avatarr = avatars_avatarrender_new(full_msginfo);
+ hooks_invoke(AVATAR_IMAGE_RENDER_HOOKLIST, avatarr);
+
+ procmsg_msginfo_free(&full_msginfo);
+
+ if (avatarr->image != NULL)
+ picture = gtk_image_get_pixbuf(GTK_IMAGE(avatarr->image));
+
+#ifndef USE_ALT_ADDRBOOK
addressbook_add_contact(msginfo->fromname, from, NULL, picture);
#else
if (addressadd_selection(msginfo->fromname, from, NULL, picture)) {
debug_print( "addressbook_add_contact - added\n" );
}
#endif
- if (image)
- gtk_widget_destroy(image);
+ avatars_avatarrender_free(avatarr);
}
static void create_filter_cb(GtkAction *gaction, gpointer data)