/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999,2000 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2001 Hiroyuki Yamamoto
*
* 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
/* create GtkText widgets for single-byte and multi-byte character */
text_sb = gtk_text_new(NULL, NULL);
text_mb = gtk_text_new(NULL, NULL);
+ GTK_TEXT(text_sb)->default_tab_width = 8;
+ GTK_TEXT(text_mb)->default_tab_width = 8;
gtk_widget_show(text_sb);
gtk_widget_show(text_mb);
gtk_text_set_word_wrap(GTK_TEXT(text_sb), TRUE);
gtk_signal_connect(GTK_OBJECT(text_sb), "key_press_event",
GTK_SIGNAL_FUNC(textview_key_pressed),
textview);
- gtk_signal_connect(GTK_OBJECT(text_sb), "button_press_event",
- GTK_SIGNAL_FUNC(textview_button_pressed),
- textview);
+ gtk_signal_connect_after(GTK_OBJECT(text_sb), "button_press_event",
+ GTK_SIGNAL_FUNC(textview_button_pressed),
+ textview);
gtk_signal_connect(GTK_OBJECT(text_mb), "key_press_event",
GTK_SIGNAL_FUNC(textview_key_pressed),
textview);
- gtk_signal_connect(GTK_OBJECT(text_mb), "button_press_event",
- GTK_SIGNAL_FUNC(textview_button_pressed),
- textview);
+ gtk_signal_connect_after(GTK_OBJECT(text_mb), "button_press_event",
+ GTK_SIGNAL_FUNC(textview_button_pressed),
+ textview);
gtk_widget_show(scrolledwin_sb);
gtk_widget_show(scrolledwin_mb);
textview->text_mb = text_mb;
textview->text_is_mb = FALSE;
textview->uri_list = NULL;
+ textview->body_pos = 0;
+ textview->cur_pos = 0;
return textview;
}
/* display attached RFC822 single text message */
if (mimeinfo->parent && mimeinfo->mime_type == MIME_MESSAGE_RFC822) {
+ if (headers) procheader_header_array_destroy(headers);
if (!mimeinfo->sub || mimeinfo->sub->children) return;
headers = textview_scan_header(textview, fp);
mimeinfo = mimeinfo->sub;
} else if (!mimeinfo->parent &&
mimeinfo->mime_type == MIME_MESSAGE_RFC822) {
+ if (headers) procheader_header_array_destroy(headers);
if (!mimeinfo->sub) return;
headers = textview_scan_header(textview, fp);
mimeinfo = mimeinfo->sub;
text = GTK_TEXT(textview->text);
gtk_text_freeze(text);
+ textview->body_pos = 0;
+ textview->cur_pos = 0;
+
if (headers) {
textview_show_header(textview, headers);
- procheader_header_array_destroy(headers);
+ procheader_header_array_destroy(headers);
}
tmpfp = procmime_decode_content(NULL, fp, mimeinfo);
gtk_text_thaw(text);
}
+#define TEXT_INSERT(str) \
+ gtk_text_insert(text, textview->msgfont, NULL, NULL, str, -1)
+
void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
{
GtkText *text;
gtk_text_freeze(text);
- gtk_text_insert
- (text, textview->msgfont, NULL, NULL,
- _("To save this part, pop up the context menu with\n"), -1);
- gtk_text_insert
- (text, textview->msgfont, NULL, NULL,
- _("right click and select `Save as...', or press `y' key.\n\n"), -1);
-
- gtk_text_insert
- (text, textview->msgfont, NULL, NULL,
- _("To display this part as a text message, select\n"), -1);
- gtk_text_insert
- (text, textview->msgfont, NULL, NULL,
- _("`Display as text', or press `t' key.\n\n"), -1);
-
- gtk_text_insert
- (text, textview->msgfont, NULL, NULL,
- _("To open this part with external program, select `Open',\n"), -1);
- gtk_text_insert
- (text, textview->msgfont, NULL, NULL,
- _("or double-click, or click the center button, or press `l' key."), -1);
+ TEXT_INSERT(_("To save this part, pop up the context menu with "));
+ TEXT_INSERT(_("right click and select `Save as...', "));
+ TEXT_INSERT(_("or press `y' key.\n\n"));
+
+ TEXT_INSERT(_("To display this part as a text message, select "));
+ TEXT_INSERT(_("`Display as text', or press `t' key.\n\n"));
+
+ TEXT_INSERT(_("To open this part with external program, select "));
+ TEXT_INSERT(_("`Open' or `Open with...', "));
+ TEXT_INSERT(_("or double-click, or click the center button, "));
+ TEXT_INSERT(_("or press `l' key."));
gtk_text_thaw(text);
}
gtk_text_freeze(text);
if (partinfo->sigstatus_full == NULL) {
- gtk_text_insert
- (text, textview->msgfont, NULL, NULL,
- _("This signature has not been checked yet.\n"), -1);
- gtk_text_insert
- (text, textview->msgfont, NULL, NULL,
- _("To check it, pop up the context menu with\n"), -1);
- gtk_text_insert
- (text, textview->msgfont, NULL, NULL,
- _("right click and select `Check signature'.\n"), -1);
+ TEXT_INSERT(_("This signature has not been checked yet.\n"));
+ TEXT_INSERT(_("To check it, pop up the context menu with\n"));
+ TEXT_INSERT(_("right click and select `Check signature'.\n"));
} else {
- gtk_text_insert(text, textview->msgfont, NULL, NULL,
- partinfo->sigstatus_full, -1);
+ TEXT_INSERT(partinfo->sigstatus_full);
}
gtk_text_thaw(text);
}
#endif /* USE_GPGME */
+#undef TEXT_INSERT
+
static void textview_show_html(TextView *textview, FILE *fp,
CodeConverter *conv)
{
!isspace(ch) && \
!strchr("()<>\"", (ch)))
+#define IS_QUOTE(ch) ((ch) == '\'' || (ch) == '"')
+
/* get_email_part() - retrieves an email address. Returns TRUE if succesful */
static gboolean get_email_part(const gchar *start, const gchar *scanpos,
const gchar **bp, const gchar **ep)
/* more complex than the uri part because we need to scan back and forward starting from
* the scan position. */
gboolean result = FALSE;
- const gchar *bp_;
- const gchar *ep_;
+ const gchar *bp_ = NULL;
+ const gchar *ep_ = NULL;
+
+ /* the informative part of the email address (describing the name
+ * of the email address owner) may contain quoted parts. the
+ * closure stack stores the last encountered quotes. */
+ gchar closure_stack[128];
+ gchar *ptr = closure_stack;
g_return_val_if_fail(start != NULL, FALSE);
g_return_val_if_fail(scanpos != NULL, FALSE);
}
}
- /* we now have at least the address. now see if this is <bracketed>; in this
- * case we also scan for the informative part. we could make this a useful
- * function because it tries to parse out an email address backwards. :) */
- if (result) {
- if ( ((bp_ - 1 > start) && *(bp_ - 1) == '<') && (*ep_ == '>')) {
-
- /* the informative part of the email address (describing the name
- * of the email address owner) may contain quoted parts. the
- * closure stack stores the last encountered quotes. */
- char closure_stack[128];
- char *ptr = closure_stack;
-#define FULL_STACK() ((ptr - closure_stack) >= sizeof closure_stack)
-#define IN_STACK() (ptr > closure_stack)
+ if (!result) return FALSE;
+
+ /* skip if it's between quotes "'alfons@proteus.demon.nl'" <alfons@proteus.demon.nl> */
+ if (bp_ - 1 > start && IS_QUOTE(*(bp_ - 1)) && IS_QUOTE(*ep_))
+ return FALSE;
+
+ /* see if this is <bracketed>; in this case we also scan for the informative part. */
+ if (bp_ - 1 <= start || *(bp_ - 1) != '<' || *ep_ != '>')
+ return TRUE;
+
+#define FULL_STACK() ((size_t) (ptr - closure_stack) >= sizeof closure_stack)
+#define IN_STACK() (ptr > closure_stack)
/* has underrun check */
-#define POP_STACK() if(IN_STACK()) --ptr
+#define POP_STACK() if(IN_STACK()) --ptr
/* has overrun check */
-#define PUSH_STACK(c) if(!FULL_STACK()) *ptr++ = (c); else return TRUE
+#define PUSH_STACK(c) if(!FULL_STACK()) *ptr++ = (c); else return TRUE
/* has underrun check */
#define PEEK_STACK() (IN_STACK() ? *(ptr - 1) : 0)
- ep_++;
-
- /* scan for the informative part. */
-
- for (bp_ -= 2; bp_ >= start; bp_--) {
- /* if closure on the stack keep scanning */
- if (PEEK_STACK() == *bp_) {
- POP_STACK();
- }
- else {
- if (*bp_ == '\'' || *bp_ == '"') {
- PUSH_STACK(*bp_);
- }
- else {
- /* if nothing in the closure stack, do the special conditions
- * the following if..else expression simply checks whether
- * a token is acceptable. if not acceptable, the clause
- * should terminate the loop with a 'break' */
- if (!PEEK_STACK()) {
- if ( *bp_ == '-'
- && (((bp_ - 1) >= start) && isalnum(*(bp_ - 1)))
- && (((bp_ + 1) < ep_) && isalnum(*(bp_ + 1))) ) {
- /* hyphens are allowed, but only in between alnums */
- }
- else if ( !ispunct(*bp_) ) {
- /* but anything not being a punctiation is ok */
- }
- else {
- break; /* anything else is rejected */
- }
- }
- }
- }
+ ep_++;
+
+ /* scan for the informative part. */
+ for (bp_ -= 2; bp_ >= start; bp_--) {
+ /* if closure on the stack keep scanning */
+ if (PEEK_STACK() == *bp_) {
+ POP_STACK();
+ continue;
+ }
+ if (*bp_ == '\'' || *bp_ == '"') {
+ PUSH_STACK(*bp_);
+ continue;
+ }
+
+ /* if nothing in the closure stack, do the special conditions
+ * the following if..else expression simply checks whether
+ * a token is acceptable. if not acceptable, the clause
+ * should terminate the loop with a 'break' */
+ if (!PEEK_STACK()) {
+ if (*bp_ == '-'
+ && (((bp_ - 1) >= start) && isalnum(*(bp_ - 1)))
+ && (((bp_ + 1) < ep_) && isalnum(*(bp_ + 1)))) {
+ /* hyphens are allowed, but only in
+ between alnums */
+ } else if (!ispunct(*bp_)) {
+ /* but anything not being a punctiation
+ is ok */
+ } else {
+ break; /* anything else is rejected */
}
-
- bp_++;
+ }
+ }
+
+ bp_++;
#undef PEEK_STACK
#undef PUSH_STACK
#undef IN_STACK
#undef FULL_STACK
- /* scan forward (should start with an alnum) */
- for (; *bp_ != '<' && isspace(*bp_) && *bp_ != '"'; bp_++)
- ;
+ /* scan forward (should start with an alnum) */
+ for (; *bp_ != '<' && isspace(*bp_) && *bp_ != '"'; bp_++)
+ ;
+
+ *ep = ep_;
+ *bp = bp_;
- *ep = ep_;
- *bp = bp_;
- }
- }
return result;
}
+#undef IS_QUOTE
#undef IS_RFC822_CHAR
static gchar *make_email_string(const gchar *bp, const gchar *ep)
/* textview_make_clickable_parts() - colorizes clickable parts */
static void textview_make_clickable_parts(TextView *textview,
- GdkFont *font,
+ GdkFont *font,
GdkColor *fg_color,
GdkColor *uri_color,
const gchar *linebuf)
if (scanpos) {
/* check if URI can be parsed */
if (parser[last_index].parse(linebuf, scanpos, &bp, &ep)
- && (ep - bp - 1) > strlen(parser[last_index].needle)) {
+ && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
ADD_TXT_POS(bp, ep, last_index);
walk = ep;
} else
normal_text,
last->bp - normal_text);
uri->uri = parser[last->pti].build_uri(last->bp,
- last->ep);
+ last->ep);
uri->start = gtk_text_get_point(text);
gtk_text_insert(text, font, uri_color,
NULL, last->bp, last->ep - last->bp);
textview_make_clickable_parts(textview, textview->msgfont,
fg_color, &uri_color, buf);
else
- gtk_text_insert(text, textview->msgfont, fg_color, NULL,
- buf, -1);
+ textview_make_clickable_parts(textview, textview->msgfont,
+ fg_color, NULL, buf);
}
void textview_clear(TextView *textview)
GtkText *text = GTK_TEXT(textview->text);
gtk_text_freeze(text);
- gtk_text_backward_delete(text, gtk_text_get_length(text));
+ gtk_text_set_point(text, 0);
+ gtk_text_forward_delete(text, gtk_text_get_length(text));
gtk_text_thaw(text);
textview_uri_list_remove_all(textview->uri_list);
correctly, so it must be single-byte mode. */
if (MB_CUR_MAX > 1) {
if (codeset) {
- if (!strncasecmp(codeset, "ISO-8859-", 9) ||
- !strncasecmp(codeset, "KOI8-", 5) ||
- !strncasecmp(codeset, "CP", 2) ||
- !strncasecmp(codeset, "WINDOWS-", 8) ||
- !strcasecmp(codeset, "BALTIC"))
+ if (!g_strncasecmp(codeset, "ISO-8859-", 9) ||
+ !g_strcasecmp(codeset, "BALTIC"))
+ use_fontset = FALSE;
+ else if (conv_get_current_charset() != C_EUC_JP &&
+ (!g_strncasecmp(codeset, "KOI8-", 5) ||
+ !g_strncasecmp(codeset, "CP", 2) ||
+ !g_strncasecmp(codeset, "WINDOWS-", 8)))
use_fontset = FALSE;
}
} else
H_ORGANIZATION = 11,
};
+void textview_set_position(TextView *textview, gint pos)
+{
+ if (pos < 0) {
+ textview->cur_pos =
+ gtk_text_get_length(GTK_TEXT(textview->text));
+ } else {
+ textview->cur_pos = pos;
+ }
+}
+
static GPtrArray *textview_scan_header(TextView *textview, FILE *fp)
{
gchar buf[BUFFSIZE];
for (i = 0; i < headers->len; i++) {
header = g_ptr_array_index(headers, i);
- if (!strcasecmp(header->name, dp->name)) {
+ if (procheader_headername_equal(header->name,
+ dp->name)) {
if (dp->hidden)
procheader_header_free(header);
else
}
}
- g_ptr_array_free(headers, TRUE);
+ g_ptr_array_free(headers, FALSE);
+
return sorted_headers;
}
gtk_text_insert(text, textview->boldfont, NULL, NULL,
header->name, -1);
- gtk_text_insert(text, textview->boldfont, NULL, NULL, ":", 2);
-
- if (!strcasecmp(header->name, "Subject") ||
- !strcasecmp(header->name, "From") ||
- !strcasecmp(header->name, "To") ||
- !strcasecmp(header->name, "Cc"))
+ if (header->name[strlen(header->name) - 1] != ' ')
+ gtk_text_insert(text, textview->boldfont,
+ NULL, NULL, " ", 1);
+
+ if (procheader_headername_equal(header->name, "Subject") ||
+ procheader_headername_equal(header->name, "From") ||
+ procheader_headername_equal(header->name, "To") ||
+ procheader_headername_equal(header->name, "Cc"))
unfold_line(header->body);
if (prefs_common.enable_color &&
- (!strncmp(header->name, "X-Mailer", 8) ||
- !strncmp(header->name, "X-Newsreader", 12)) &&
+ (procheader_headername_equal(header->name, "X-Mailer") ||
+ procheader_headername_equal(header->name,
+ "X-Newsreader")) &&
strstr(header->body, "Sylpheed") != NULL)
gtk_text_insert(text, NULL, &emphasis_color, NULL,
header->body, -1);
NULL, NULL, &uri_color,
header->body);
} else {
- gtk_text_insert(text, NULL, NULL, NULL,
- header->body, -1);
+ textview_make_clickable_parts(textview,
+ NULL, NULL, NULL,
+ header->body);
}
gtk_text_insert(text, textview->msgfont, NULL, NULL, "\n", 1);
}
gtk_text_insert(text, textview->msgfont, NULL, NULL, "\n", 1);
gtk_text_thaw(text);
+ textview->body_pos = gtk_text_get_length(text);
+}
+
+gboolean textview_search_string(TextView *textview, const gchar *str,
+ gboolean case_sens)
+{
+ GtkText *text = GTK_TEXT(textview->text);
+ gint pos;
+ wchar_t *wcs;
+ gint len;
+ gint text_len;
+ gboolean found = FALSE;
+
+ g_return_val_if_fail(str != NULL, FALSE);
+
+ wcs = strdup_mbstowcs(str);
+ g_return_val_if_fail(wcs != NULL, FALSE);
+ len = wcslen(wcs);
+ pos = textview->cur_pos;
+ if (pos < textview->body_pos)
+ pos = textview->body_pos;
+ text_len = gtk_text_get_length(text);
+ if (text_len - pos < len) {
+ g_free(wcs);
+ return FALSE;
+ }
+
+ for (; pos < text_len; pos++) {
+ if (text_len - pos < len) break;
+ if (gtkut_text_match_string(text, pos, wcs, len, case_sens)
+ == TRUE) {
+ gtk_editable_set_position(GTK_EDITABLE(text),
+ pos + len);
+ gtk_editable_select_region(GTK_EDITABLE(text),
+ pos, pos + len);
+ textview_set_position(textview, pos + len);
+ found = TRUE;
+ break;
+ }
+ if (text_len - pos == len) break;
+ }
+
+ g_free(wcs);
+ return found;
+}
+
+gboolean textview_search_string_backward(TextView *textview, const gchar *str,
+ gboolean case_sens)
+{
+ GtkText *text = GTK_TEXT(textview->text);
+ gint pos;
+ wchar_t *wcs;
+ gint len;
+ gint text_len;
+ gboolean found = FALSE;
+
+ g_return_val_if_fail(str != NULL, FALSE);
+
+ wcs = strdup_mbstowcs(str);
+ g_return_val_if_fail(wcs != NULL, FALSE);
+ len = wcslen(wcs);
+ pos = textview->cur_pos;
+ text_len = gtk_text_get_length(text);
+ if (text_len - textview->body_pos < len) {
+ g_free(wcs);
+ return FALSE;
+ }
+ if (pos <= textview->body_pos || text_len - pos < len)
+ pos = text_len - len;
+
+ for (; pos >= textview->body_pos; pos--) {
+ if (gtkut_text_match_string(text, pos, wcs, len, case_sens)
+ == TRUE) {
+ gtk_editable_set_position(GTK_EDITABLE(text), pos);
+ gtk_editable_select_region(GTK_EDITABLE(text),
+ pos, pos + len);
+ textview_set_position(textview, pos - 1);
+ found = TRUE;
+ break;
+ }
+ if (pos == textview->body_pos) break;
+ }
+
+ g_free(wcs);
+ return found;
}
void textview_scroll_one_line(TextView *textview, gboolean up)
static void textview_button_pressed(GtkWidget *widget, GdkEventButton *event,
TextView *textview)
{
+ textview->cur_pos =
+ gtk_editable_get_position(GTK_EDITABLE(textview->text));
+
if (event &&
- ((event->button == 1 && event->type == GDK_2BUTTON_PRESS)
- || event->button == 2
- || event->button == 3)) {
+ ((event->button == 1 && event->type == GDK_2BUTTON_PRESS)
+ || event->button == 2 || event->button == 3)) {
GSList *cur;
- guint current_pos;
-
- current_pos = GTK_EDITABLE(textview->text)->current_pos;
for (cur = textview->uri_list; cur != NULL; cur = cur->next) {
RemoteURI *uri = (RemoteURI *)cur->data;
- if (current_pos >= uri->start &&
- current_pos < uri->end) {
- if (!strncasecmp(uri->uri, "mailto:", 7)) {
- compose_new_with_recipient
- (NULL, uri->uri + 7);
- }
- else
+ if (textview->cur_pos >= uri->start &&
+ textview->cur_pos < uri->end) {
+ if (!g_strncasecmp(uri->uri, "mailto:", 7)) {
+ if (event->button == 3) {
+ gchar *fromname, *fromaddress;
+ /* extract url */
+ fromaddress = g_strdup(uri->uri + 7);
+ /* Hiroyuki: please put this function in utils.c! */
+ fromname = procheader_get_fromname(fromaddress);
+ extract_address(fromaddress);
+ g_message("adding from textview %s <%s>", fromname, fromaddress);
+ // Add to address book - Match
+ addressbook_add_contact( fromname, fromaddress, NULL );
+ g_free(fromaddress);
+ g_free(fromname);
+ } else {
+ compose_new_with_recipient
+ (NULL, uri->uri + 7);
+ }
+ } else {
open_uri(uri->uri,
prefs_common.uri_cmd);
- }
+ }
+ }
}
}
}