/*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2015 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/>.
- *
+ *
*/
#ifdef HAVE_CONFIG_H
#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
-#if HAVE_LIBCOMPFACE
-# include <compface.h>
-#endif
-
-#if HAVE_LIBCOMPFACE
-#define XPM_XFACE_HEIGHT (HEIGHT + 3) /* 3 = 1 header + 2 colors */
-#endif
#include "main.h"
#include "summaryview.h"
#include "menu.h"
#include "image_viewer.h"
#include "filesel.h"
-#include "base64.h"
#include "inputdialog.h"
#include "timing.h"
#include "tags.h"
#include "manage_window.h"
+#include "folder_item_prefs.h"
+#include "hooks.h"
+#include "avatars.h"
static GdkColor quote_colors[3] = {
{(gulong)0, (gushort)0, (gushort)0, (gushort)0},
cm_return_if_fail(mimeinfo != NULL);
cm_return_if_fail(fp != NULL);
- if ((mimeinfo->type == MIMETYPE_MULTIPART) ||
- ((mimeinfo->type == MIMETYPE_MESSAGE) && !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822"))) {
- textview->loading = TRUE;
- textview->stop_loading = FALSE;
-
- textview_clear(textview);
- textview_add_parts(textview, mimeinfo);
-
- textview->loading = FALSE;
- textview->stop_loading = FALSE;
- END_TIMING();
- return;
- }
textview->loading = TRUE;
textview->stop_loading = FALSE;
- if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0)
- perror("fseek");
-
textview_clear(textview);
- if (mimeinfo->type == MIMETYPE_MULTIPART)
+ if (mimeinfo->type == MIMETYPE_MULTIPART ||
+ (mimeinfo->type == MIMETYPE_MESSAGE && !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822"))) {
textview_add_parts(textview, mimeinfo);
- else
+ } else {
+ if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0)
+ perror("fseek");
+
textview_write_body(textview, mimeinfo);
+ }
textview->loading = FALSE;
textview->stop_loading = FALSE;
+ textview_set_position(textview, 0);
+
END_TIMING();
}
const gchar *name;
gchar *content_type;
gint charcount;
+
START_TIMING("");
cm_return_if_fail(mimeinfo != NULL);
END_TIMING();
return;
}
- fseek(fp, mimeinfo->offset, SEEK_SET);
+ if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0) {
+ FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
+ fclose(fp);
+ END_TIMING();
+ return;
+ }
headers = textview_scan_header(textview, fp);
if (headers) {
if (charcount > 0)
filename = procmime_get_tmp_file_name(mimeinfo);
if ((err = procmime_get_part(filename, mimeinfo)) < 0) {
- g_warning("Can't get the image file.(%s)", strerror(-err));
+ g_warning("Can't get the image file.(%s)", g_strerror(-err));
g_free(filename);
END_TIMING();
return;
if (prefs_common.display_header && (charcount > 0))
gtk_text_buffer_insert(buffer, &iter, "\n", 1);
+ if (!gtk_text_buffer_get_mark(buffer, "body_start")) {
+ gtk_text_buffer_get_end_iter(buffer, &iter);
+ gtk_text_buffer_create_mark(buffer, "body_start", &iter, TRUE);
+ }
+
textview_write_body(textview, mimeinfo);
+
+ if (!gtk_text_buffer_get_mark(buffer, "body_end")) {
+ gtk_text_buffer_get_end_iter(buffer, &iter);
+ gtk_text_buffer_create_mark(buffer, "body_end", &iter, TRUE);
+ }
}
END_TIMING();
}
GtkTextBuffer *buffer;
GtkTextIter iter;
const gchar *name;
- gchar *content_type;
+ gchar *content_type, *shortcut;
+ GtkUIManager *ui_manager;
if (!partinfo) return;
+ if (textview->messageview->window != NULL)
+ ui_manager = textview->messageview->ui_manager;
+ else
+ ui_manager = textview->messageview->mainwin->ui_manager;
+
textview_set_font(textview, NULL);
textview_clear(textview);
TEXTVIEW_INSERT(_(" - To save, select "));
TEXTVIEW_INSERT_LINK(_("'Save as...'"), "sc://save_as", NULL);
#ifndef GENERIC_UMPC
- TEXTVIEW_INSERT(_(" (Shortcut key: 'y')"));
+ TEXTVIEW_INSERT(_(" (Shortcut key: '"));
+ shortcut = cm_menu_item_get_shortcut(ui_manager, "Menu/File/SavePartAs");
+ TEXTVIEW_INSERT(shortcut);
+ g_free(shortcut);
+ TEXTVIEW_INSERT("')");
#endif
TEXTVIEW_INSERT("\n");
TEXTVIEW_INSERT_LINK(_("'Display as text'"), "sc://display_as_text", NULL);
#ifndef GENERIC_UMPC
- TEXTVIEW_INSERT(_(" (Shortcut key: 't')"));
+ TEXTVIEW_INSERT(_(" (Shortcut key: '"));
+ shortcut = cm_menu_item_get_shortcut(ui_manager, "Menu/View/Part/AsText");
+ TEXTVIEW_INSERT(shortcut);
+ g_free(shortcut);
+ TEXTVIEW_INSERT("')");
#endif
TEXTVIEW_INSERT("\n");
TEXTVIEW_INSERT_LINK(_("'Open'"), "sc://open", NULL);
#ifndef GENERIC_UMPC
- TEXTVIEW_INSERT(_(" (Shortcut key: 'l')\n"));
+ TEXTVIEW_INSERT(_(" (Shortcut key: '"));
+ shortcut = cm_menu_item_get_shortcut(ui_manager, "Menu/View/Part/Open");
+ TEXTVIEW_INSERT(shortcut);
+ g_free(shortcut);
+ TEXTVIEW_INSERT("')\n");
TEXTVIEW_INSERT(_(" (alternately double-click, or click the middle "));
TEXTVIEW_INSERT(_("mouse button)\n"));
#ifndef G_OS_WIN32
TEXTVIEW_INSERT(_(" - Or use "));
TEXTVIEW_INSERT_LINK(_("'Open with...'"), "sc://open_with", NULL);
- TEXTVIEW_INSERT(_(" (Shortcut key: 'o')"));
+ TEXTVIEW_INSERT(_(" (Shortcut key: '"));
+ shortcut = cm_menu_item_get_shortcut(ui_manager, "Menu/View/Part/OpenWith");
+ TEXTVIEW_INSERT(shortcut);
+ g_free(shortcut);
+ TEXTVIEW_INSERT("')");
#endif
#endif
TEXTVIEW_INSERT("\n");
filename = procmime_get_tmp_file_name(mimeinfo);
if (procmime_get_part(filename, mimeinfo) == 0) {
tmpfp = g_fopen(filename, "rb");
- textview_show_ertf(textview, tmpfp, conv);
- fclose(tmpfp);
+ if (tmpfp) {
+ textview_show_ertf(textview, tmpfp, conv);
+ fclose(tmpfp);
+ }
claws_unlink(filename);
}
g_free(filename);
if (pipe(pfd) < 0) {
g_snprintf(buf, sizeof(buf),
- "pipe failed for textview\n\n%s\n", strerror(errno));
+ "pipe failed for textview\n\n%s\n", g_strerror(errno));
textview_write_line(textview, buf, conv, TRUE);
goto textview_default;
}
pid = fork();
if (pid < 0) {
g_snprintf(buf, sizeof(buf),
- "fork failed for textview\n\n%s\n", strerror(errno));
+ "fork failed for textview\n\n%s\n", g_strerror(errno));
textview_write_line(textview, buf, conv, TRUE);
close(pfd[0]);
close(pfd[1]);
FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
return;
}
- fseek(tmpfp, mimeinfo->offset, SEEK_SET);
+ if (fseek(tmpfp, mimeinfo->offset, SEEK_SET) < 0) {
+ FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
+ fclose(tmpfp);
+ return;
+ }
debug_print("Viewing text content of type: %s (length: %d)\n", mimeinfo->subtype, mimeinfo->length);
while (((i = ftell(tmpfp)) < mimeinfo->offset + mimeinfo->length) &&
(fgets(buf, sizeof(buf), tmpfp) != NULL)
gtk_text_buffer_get_end_iter(buffer, &iter);
/* parse for clickable parts, and build a list of begin and end positions */
- for (walk = mybuf, n = 0;;) {
+ for (walk = mybuf;;) {
gint last_index = PARSE_ELEMS;
gchar *scanpos = NULL;
offset = gtk_text_iter_get_offset(&start_iter);
/* parse for clickable parts, and build a list of begin and end positions */
- for (walk = mybuf, n = 0;;) {
+ for (walk = mybuf;;) {
gint last_index = PARSE_ELEMS;
gchar *scanpos = NULL;
uri = g_new0(ClickableText, 1);
uri->uri = g_strdup("");
uri->data = g_strdup(buf);
+ uri->data_len = strlen(uri->data);
uri->start = gtk_text_iter_get_offset(&iter);
uri->is_quote = TRUE;
uri->quote_level = real_quotelevel;
textview->prev_quote_level = -1;
goto do_quote;
}
- e_len = lasturi->data ? strlen(lasturi->data):0;
+ e_len = lasturi->data ? lasturi->data_len:0;
n_len = strlen(buf);
lasturi->data = g_realloc((gchar *)lasturi->data, e_len + n_len + 1);
strcpy((gchar *)lasturi->data + e_len, buf);
*((gchar *)lasturi->data + e_len + n_len) = '\0';
+ lasturi->data_len += n_len;
}
}
} else {
void textview_write_link(TextView *textview, const gchar *str,
const gchar *uri, CodeConverter *conv)
{
- GdkColor *link_color = NULL;
GtkTextView *text;
GtkTextBuffer *buffer;
GtkTextIter iter;
if (bufp > buf)
gtk_text_buffer_insert(buffer, &iter, buf, bufp - buf);
- if (prefs_common.enable_color) {
- link_color = &uri_color;
- }
r_uri = g_new0(ClickableText, 1);
r_uri->uri = g_strdup(uri);
r_uri->start = gtk_text_iter_get_offset(&iter);
buffer = gtk_text_view_get_buffer(text);
gtk_text_buffer_set_text(buffer, "", -1);
+ if (gtk_text_buffer_get_mark(buffer, "body_start"))
+ gtk_text_buffer_delete_mark_by_name(buffer, "body_start");
+ if (gtk_text_buffer_get_mark(buffer, "body_end"))
+ gtk_text_buffer_delete_mark_by_name(buffer, "body_end");
TEXTVIEW_STATUSBAR_POP(textview);
textview_uri_list_remove_all(textview->uri_list);
if (textview->image)
gtk_widget_destroy(textview->image);
textview->image = NULL;
+ textview->avatar_type = 0;
if (textview->messageview->mainwin->cursor_count == 0) {
textview_set_cursor(window, text_cursor);
gtkut_text_view_set_position(text, pos);
}
-static gboolean header_is_internal(Header *header)
-{
- const gchar *internal_hdrs[] =
- {"AF:", "NF:", "PS:", "SRH:", "SFN:", "DSR:", "MID:",
- "CFG:", "PT:", "S:", "RQ:", "SSV:", "NSV:", "SSH:",
- "R:", "MAID:", "SCF:", "RMID:", "FMID:", "NAID:",
- "X-Claws-Account-Id:", "X-Claws-Sign:", "X-Claws-Encrypt:",
- "X-Claws-Privacy-System:", "X-Claws-End-Special-Headers:",
- "X-Sylpheed-Account-Id:", "X-Sylpheed-Sign:", "X-Sylpheed-Encrypt:",
- "X-Claws-Auto-Wrapping:", "X-Claws-Auto-Indent:",
- "X-Sylpheed-Privacy-System:", "X-Sylpheed-End-Special-Headers:",
- NULL};
- int i;
-
- for (i = 0; internal_hdrs[i]; i++) {
- if (!strcmp(header->name, internal_hdrs[i]))
- return TRUE;
- }
- return FALSE;
-}
-
static GPtrArray *textview_scan_header(TextView *textview, FILE *fp)
{
gchar buf[BUFFSIZE];
sorted_headers = g_ptr_array_new();
for (i = 0; i < headers->len; i++) {
header = g_ptr_array_index(headers, i);
- if (!header_is_internal(header))
+ if (!procheader_header_is_internal(header->name))
g_ptr_array_add(sorted_headers, header);
else
procheader_header_free(header);
if (prefs_common.show_other_header) {
for (i = 0; i < headers->len; i++) {
header = g_ptr_array_index(headers, i);
- if (!header_is_internal(header)) {
+ if (!procheader_header_is_internal(header->name)) {
g_ptr_array_add(sorted_headers, header);
} else {
procheader_header_free(header);
return sorted_headers;
}
-static void textview_show_face(TextView *textview)
+static void textview_show_avatar(TextView *textview)
{
GtkAllocation allocation;
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
MsgInfo *msginfo = textview->messageview->msginfo;
int x = 0;
+ AvatarRender *avatarr;
- if (prefs_common.display_header_pane
- || !prefs_common.display_xface)
+ if (prefs_common.display_header_pane || !prefs_common.display_xface)
goto bail;
- if (!msginfo->extradata || !msginfo->extradata->face) {
+ avatarr = avatars_avatarrender_new(msginfo);
+ hooks_invoke(AVATAR_IMAGE_RENDER_HOOKLIST, avatarr);
+
+ if (!avatarr->image) {
+ avatars_avatarrender_free(avatarr);
goto bail;
}
if (textview->image)
gtk_widget_destroy(textview->image);
- textview->image = face_get_from_header(msginfo->extradata->face);
- cm_return_if_fail(textview->image != NULL);
+ textview->image = avatarr->image;
+ textview->avatar_type = avatarr->type;
+ avatarr->image = NULL; /* avoid destroying */
+ avatars_avatarrender_free(avatarr);
gtk_widget_show(textview->image);
GTK_TEXT_WINDOW_TEXT, x, 5);
gtk_widget_show_all(textview->text);
-
return;
bail:
if (textview->image)
gtk_widget_destroy(textview->image);
textview->image = NULL;
+ textview->avatar_type = 0;
}
void textview_show_icon(TextView *textview, const gchar *stock_id)
return;
}
-#if HAVE_LIBCOMPFACE
-static void textview_show_xface(TextView *textview)
-{
- GtkAllocation allocation;
- MsgInfo *msginfo = textview->messageview->msginfo;
- GtkTextView *text = GTK_TEXT_VIEW(textview->text);
- int x = 0;
- GdkWindow *window = NULL;
-
- if (prefs_common.display_header_pane
- || !prefs_common.display_xface)
- goto bail;
-
- if (!msginfo || !msginfo->extradata)
- goto bail;
-
- if (msginfo->extradata->face)
- return;
-
- if (!msginfo->extradata->xface || strlen(msginfo->extradata->xface) < 5) {
- goto bail;
- }
-
- if (textview->image)
- gtk_widget_destroy(textview->image);
-
- window = mainwindow_get_mainwindow() ?
- mainwindow_get_mainwindow()->window->window :
- textview->text->window;
- textview->image = xface_get_from_header(msginfo->extradata->xface,
- &textview->text->style->white,
- window);
- cm_return_if_fail(textview->image != NULL);
-
- gtk_widget_show(textview->image);
-
- gtk_widget_get_allocation(textview->text, &allocation);
- x = allocation.width - WIDTH -5;
-
- gtk_text_view_add_child_in_window(text, textview->image,
- GTK_TEXT_WINDOW_TEXT, x, 5);
-
- gtk_widget_show_all(textview->text);
-
- return;
-bail:
- if (textview->image)
- gtk_widget_destroy(textview->image);
- textview->image = NULL;
-
-}
-#endif
-
static void textview_save_contact_pic(TextView *textview)
{
#ifndef USE_NEW_ADDRBOOK
gchar *filename = NULL;
GError *error = NULL;
GdkPixbuf *picture = NULL;
-
- if (!msginfo->extradata || (!msginfo->extradata->face && !msginfo->extradata->xface))
+
+ if (!msginfo->extradata || !msginfo->extradata->avatars)
+ return;
+
+ if (textview->avatar_type > AVATAR_FACE)
return;
if (textview->image)
GError *error = NULL;
GdkPixbuf *picture = NULL;
gint w, h;
-
+ GtkAllocation allocation;
+
if (prefs_common.display_header_pane
- || !prefs_common.display_xface)
+ || !prefs_common.display_xface)
goto bail;
- if (msginfo->extradata && (msginfo->extradata->face || msginfo->extradata->xface))
+ if (msginfo->extradata && msginfo->extradata->avatars)
return;
if (textview->image)
gtk_widget_show(textview->image);
- x = textview->text->allocation.width - WIDTH -5;
+ gtk_widget_get_allocation(textview->text, &allocation);
+ x = allocation.width - WIDTH -5;
gtk_text_view_add_child_in_window(text, textview->image,
GTK_TEXT_WINDOW_TEXT, x, 5);
if (textview->image)
gtk_widget_destroy(textview->image);
textview->image = NULL;
+ textview->avatar_type = 0;
#else
/* new address book */
#endif
return tag_b == NULL ? 0:1;
if (tag_b == NULL)
- return tag_a == NULL ? 0:1;
+ return 1;
return g_utf8_collate(tag_a, tag_b);
}
"header", NULL);
}
- textview_show_face(textview);
-#if HAVE_LIBCOMPFACE
- textview_show_xface(textview);
-#endif
+ textview_show_avatar(textview);
+
textview_save_contact_pic(textview);
textview_show_contact_pic(textview);
}
static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
TextView *textview)
{
- GdkWindow *window;
+ GdkWindow *window = NULL;
SummaryView *summaryview = NULL;
MessageView *messageview = textview->messageview;
if (summaryview)
summary_pass_key_press_event(summaryview, event);
break;
- case GDK_KEY_y:
- case GDK_KEY_t:
- case GDK_KEY_l:
- case GDK_KEY_o:
- case GDK_KEY_c:
- case GDK_KEY_a:
- if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) == 0) {
- KEY_PRESS_EVENT_STOP();
- mimeview_pass_key_press_event(messageview->mimeview,
- event);
- break;
- }
- /* possible fall through */
default:
- window = gtk_widget_get_window(messageview->mainwin->window);
- if (summaryview &&
- event->window != window) {
- GdkEventKey tmpev = *event;
-
- tmpev.window = window;
- KEY_PRESS_EVENT_STOP();
- gtk_widget_event(messageview->mainwin->window,
- (GdkEvent *)&tmpev);
+ if (messageview->mainwin) {
+ window = gtk_widget_get_window(messageview->mainwin->window);
+ if (summaryview &&
+ event->window != window) {
+ GdkEventKey tmpev = *event;
+
+ tmpev.window = window;
+ KEY_PRESS_EVENT_STOP();
+ gtk_widget_event(messageview->mainwin->window,
+ (GdkEvent *)&tmpev);
+ }
}
break;
}
gchar *cmd = NULL;
gchar buf[1024];
const gchar *p;
- gchar *filename = NULL;
+ gchar *filename = NULL, *filepath = NULL;
gchar *tmp_filename = NULL;
if (uri == NULL)
subst_for_filename(filename);
+ filepath = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
+ filename, NULL);
+
tmp_filename = g_filename_from_uri(uri->uri, NULL, NULL);
- copy_file(tmp_filename, filename, FALSE);
+ copy_file(tmp_filename, filepath, FALSE);
g_free(tmp_filename);
cmd = mailcap_get_command_for_type("image/jpeg", filename);
}
if (cmd && (p = strchr(cmd, '%')) && *(p + 1) == 's' &&
!strchr(p + 2, '%'))
- g_snprintf(buf, sizeof(buf), cmd, filename);
+ g_snprintf(buf, sizeof(buf), cmd, filepath);
else {
g_warning("Image viewer command-line is invalid: '%s'", cmd);
+ g_free(filepath);
+ g_free(filename);
return;
}
execute_command_line(buf, TRUE);
+ g_free(filepath);
g_free(filename);
g_free(cmd);
filepath = g_strconcat(prefs_common.attach_save_dir,
G_DIR_SEPARATOR_S, filename, NULL);
else
- filepath = g_strdup(filename);
+ filepath = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
+ filename, NULL);
g_free(filename);
gchar *fromname, *fromaddress;
ClickableText *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
"menu_button");
- GtkWidget *image = NULL;
+ AvatarRender *avatarr = NULL;
GdkPixbuf *picture = NULL;
gboolean use_picture = FALSE;
fromname = procheader_get_fromname(fromaddress);
extract_address(fromaddress);
- if (use_picture &&
- textview->messageview->msginfo &&
- textview->messageview->msginfo->extradata &&
- textview->messageview->msginfo->extradata->face) {
- image = face_get_from_header(textview->messageview->msginfo->extradata->face);
- }
-#if HAVE_LIBCOMPFACE
- else if (use_picture &&
- textview->messageview->msginfo &&
- textview->messageview->msginfo->extradata &&
- textview->messageview->msginfo->extradata->xface) {
- image = xface_get_from_header(textview->messageview->msginfo->extradata->xface,
- &textview->text->style->white,
- mainwindow_get_mainwindow()->window->window);
+ if (use_picture) {
+ avatarr = avatars_avatarrender_new(textview->messageview->msginfo);
+ hooks_invoke(AVATAR_IMAGE_RENDER_HOOKLIST, avatarr);
+ }
+
+ if (avatarr && avatarr->image) {
+ picture = gtk_image_get_pixbuf(GTK_IMAGE(avatarr->image));
+ }
+ if (avatarr) {
+ avatars_avatarrender_free(avatarr);
}
-#endif
- if (image)
- picture = gtk_image_get_pixbuf(GTK_IMAGE(image));
#ifndef USE_NEW_ADDRBOOK
addressbook_add_contact( fromname, fromaddress, NULL, picture);