static PrefsAccount *compose_current_mail_account(void);
/* static gint compose_send (Compose *compose); */
+static gboolean compose_check_for_valid_recipient
+ (Compose *compose);
+static gboolean compose_check_entries (Compose *compose);
static gint compose_write_to_file (Compose *compose,
const gchar *file,
gboolean is_draft);
static gint compose_write_body_to_file (Compose *compose,
const gchar *file);
-static gint compose_save_to_outbox (Compose *compose,
- const gchar *file);
static gint compose_remove_reedit_target (Compose *compose);
static gint compose_queue (Compose *compose,
gint *msgnum,
"<control><alt>L", compose_wrap_line_all, 0, NULL},
{N_("/_Edit/Edit with e_xternal editor"),
"<shift><control>X", compose_ext_editor_cb, 0, NULL},
- {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
- {N_("/_Edit/Actio_ns"), NULL, NULL, 0, "<Branch>"},
#if USE_PSPELL
{N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
{N_("/_Spelling/_Check all or check selection"),
#endif /* USE_GPGME */
{N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
{N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
- {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
- {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
- {N_("/_Tool/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
- {N_("/_Tool/_Template"), NULL, NULL, 0, "<Branch>"},
+ {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
+ {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
+ {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
+ {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
+ {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
{N_("/_Help"), NULL, NULL, 0, "<Branch>"},
{N_("/_Help/_About"), NULL, about_show, 0, NULL}
};
menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
#endif
menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
- menu_set_sensitive(ifactory, "/Tool/Template", FALSE);
+ menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
gtk_widget_set_sensitive(c->insert_btn, FALSE);
gtk_widget_set_sensitive(c->attach_btn, FALSE);
if (strlen(sigfile) < 2)
return;
- sigprg = popen(sigfile+1, "rb");
+ sigprg = popen(sigfile+1, "r");
if (sigprg) {
buf = g_malloc(buf_len);
}
line_end = 1;
} else {
- if (ch_len == 1 && strchr(">:#", *cbuf))
+ if (ch_len == 1 && strchr(">|:#", *cbuf))
quoted = 1;
else if (ch_len != 1 || !isspace(*cbuf))
quoted = 0;
}
line_end = 1;
} else {
- if (line_end && ch_len == 1 && strchr(">:#", *cbuf))
+ if (line_end && ch_len == 1 && strchr(">|:#", *cbuf))
goto compose_end; /* quoted part */
line_end = 0;
gtk_stext_thaw(text);
}
+#undef WRAP_DEBUG
+#ifdef WRAP_DEBUG
+/* Darko: used when I debug wrapping */
+void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
+{
+ gint i;
+ gchar ch;
+
+ printf("%d [", pos);
+ for (i = pos; i < tlen; i++) {
+ ch = GTK_STEXT_INDEX(text, i);
+ if (breakoncr && ch == '\n')
+ break;
+ printf("%c", ch);
+ }
+ printf("]\n");
+}
+#endif
+
+typedef enum {
+ WAIT_FOR_SPACETAB,
+ WAIT_FOR_INDENTCHAR,
+ WAIT_FOR_INDENTCHARORSPACETAB
+} IndentStates;
+
+#define INDCHARS ">|:#"
+#define SPACECHARS " \t"
+
+/* return indent length, we allow:
+ > followed by spaces/tabs
+ | followed by spaces/tabs
+ uppercase characters immediately followed by >,
+ and the repeating sequences of the above */
/* return indent length */
static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
{
- gint indent_len = 0;
- gint i, ch_len;
- gchar cbuf[MB_LEN_MAX];
+ guint i_len = 0;
+ guint i, ch_len, alnum_cnt = 0;
+ IndentStates state = WAIT_FOR_INDENTCHAR;
+ gchar cb[MB_LEN_MAX];
+ gboolean is_space;
+ gboolean is_indent;
for (i = start_pos; i < text_len; i++) {
- GET_CHAR(i, cbuf, ch_len);
+ GET_CHAR(i, cb, ch_len);
if (ch_len > 1)
break;
- /* allow space, tab, > or | */
- if (cbuf[0] != ' ' && cbuf[0] != '\t' &&
- cbuf[0] != '>' && cbuf[0] != '|')
+
+ if (cb[0] == '\n')
+ break;
+
+ is_indent = strchr(INDCHARS, cb[0]) ? TRUE : FALSE;
+ is_space = strchr(SPACECHARS, cb[0]) ? TRUE : FALSE;
+
+ switch (state) {
+ case WAIT_FOR_SPACETAB:
+ if (is_space == FALSE)
+ goto out;
+ state = WAIT_FOR_INDENTCHARORSPACETAB;
+ break;
+ case WAIT_FOR_INDENTCHARORSPACETAB:
+ if (is_indent == FALSE && is_space == FALSE &&
+ !isupper(cb[0]))
+ goto out;
+ if (is_space == TRUE) {
+ alnum_cnt = 0;
+ state = WAIT_FOR_INDENTCHARORSPACETAB;
+ } else if (is_indent == TRUE) {
+ alnum_cnt = 0;
+ state = WAIT_FOR_SPACETAB;
+ } else {
+ alnum_cnt++;
+ state = WAIT_FOR_INDENTCHAR;
+ break;
+ }
+ break;
+ case WAIT_FOR_INDENTCHAR:
+ if (is_indent == FALSE && !isupper(cb[0]))
+ goto out;
+ if (is_indent == TRUE) {
+ alnum_cnt = 0;
+ state = WAIT_FOR_SPACETAB;
+ } else {
+ alnum_cnt++;
+ }
break;
- indent_len++;
+ }
+
+ i_len++;
}
- return indent_len;
+out:
+ if ((i_len > 0) && (state == WAIT_FOR_INDENTCHAR))
+ i_len -= alnum_cnt;
+
+ return i_len;
}
/* insert quotation string when line was wrapped */
-static guint ins_quote(GtkSText *text, guint quote_len, guint indent_len,
+static guint ins_quote(GtkSText *text, guint indent_len,
guint prev_line_pos, guint text_len,
gchar *quote_fmt)
{
gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
}
ins_len = indent_len;
- } else {
- gtk_stext_insert(text, NULL, NULL, NULL, quote_fmt, quote_len);
- ins_len = quote_len;
}
return ins_len;
}
-#undef WRAP_DEBUG
-#ifdef WRAP_DEBUG
-/* Darko: used when I debug wrapping */
-void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
+/* check if we should join the next line */
+static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
+ guint prev_ilen)
{
- gint i;
- gchar ch;
+ guint indent_len, ch_len;
+ gboolean do_join = FALSE;
+ gchar cbuf[MB_LEN_MAX];
- printf("%d [", pos);
- for (i = pos; i < tlen; i++) {
- ch = GTK_STEXT_INDEX(text, i);
- if (breakoncr && ch == '\n')
- break;
- printf("%c", ch);
+ indent_len = get_indent_length(text, start_pos, tlen);
+
+ if ((indent_len > 0) && (indent_len == prev_ilen)) {
+ GET_CHAR(start_pos + indent_len, cbuf, ch_len);
+ if (ch_len == 1 && (cbuf[0] != '\n'))
+ do_join = TRUE;
}
- printf("]\n");
+
+ return do_join;
}
-#endif
static void compose_wrap_line_all(Compose *compose)
{
gint line_len = 0, cur_len = 0;
gint ch_len;
gboolean is_new_line = TRUE, do_delete = FALSE;
- guint qlen = 0, i_len = 0;
+ guint i_len = 0;
gboolean linewrap_quote = TRUE;
guint linewrap_len = prefs_common.linewrap_len;
gchar *qfmt = prefs_common.quotemark;
for (; cur_pos < tlen; cur_pos++) {
/* mark position of new line - needed for quotation wrap */
if (is_new_line) {
- if (linewrap_quote) {
- qlen = gtkut_stext_str_compare
- (text, cur_pos, tlen, qfmt);
- if (qlen)
- i_len = get_indent_length
- (text, cur_pos, tlen);
- else
- i_len = 0;
- }
+ if (linewrap_quote)
+ i_len = get_indent_length(text, cur_pos, tlen);
+
is_new_line = FALSE;
p_pos = cur_pos;
#ifdef WRAP_DEBUG
- printf("new line i_len=%d qlen=%d p_pos=", i_len, qlen);
+ printf("new line i_len=%d p_pos=", i_len);
dump_text(text, p_pos, tlen, 1);
#endif
}
guint ilen;
gchar cb[MB_CUR_MAX];
+ /* should we join the next line */
+ if ((i_len != cur_len) && do_delete &&
+ join_next_line(text, cur_pos + 1, tlen, i_len))
+ do_delete = TRUE;
+ else
+ do_delete = FALSE;
+
#ifdef WRAP_DEBUG
- printf("found CR at %d next line is ", cur_pos);
+ printf("found CR at %d do_del is %d next line is ",
+ cur_pos, do_delete);
dump_text(text, cur_pos + 1, tlen, 1);
#endif
- /* if it's just quotation + newline skip it */
- if (i_len && (cur_pos + 1 < tlen)) {
- /* check if text at new line matches indent */
- ilen = gtkut_stext_str_compare_n
- (text, cur_pos + 1, p_pos, i_len, tlen);
- if (cur_pos + ilen < tlen) {
- GET_CHAR(cur_pos + ilen + 1, cb, clen);
- /* no need to join the lines */
- if (clen == 1 && cb[0] == '\n')
- do_delete = FALSE;
- }
- /* if it's just newline skip it */
- } else if (do_delete && (cur_pos + 1 < tlen)) {
- GET_CHAR(cur_pos + 1, cb, clen);
- /* no need to join the lines */
- if (clen == 1 && cb[0] == '\n')
- do_delete = FALSE;
- }
/* skip delete if it is continuous URL */
if (do_delete && (line_pos - p_pos <= i_len) &&
do_delete = FALSE;
#ifdef WRAP_DEBUG
- printf("qlen=%d l_len=%d wrap_len=%d do_del=%d\n",
- qlen, line_len, linewrap_len, do_delete);
+ printf("l_len=%d wrap_len=%d do_del=%d\n",
+ line_len, linewrap_len, do_delete);
#endif
/* should we delete to perform smart wrapping */
if (line_len < linewrap_len && do_delete) {
(text, ilen);
tlen -= ilen;
}
- } else if (qlen) {
- if (gtkut_stext_str_compare
- (text, cur_pos, tlen, qfmt)) {
- gtk_stext_forward_delete
- (text, qlen);
- tlen -= qlen;
- }
}
GET_CHAR(cur_pos, cb, clen);
cur_pos = p_pos - 1;
line_pos = cur_pos;
line_len = cur_len = 0;
- qlen = 0;
do_delete = FALSE;
is_new_line = TRUE;
#ifdef WRAP_DEBUG
/* mark new line beginning */
line_pos = cur_pos + 1;
line_len = cur_len = 0;
- qlen = 0;
do_delete = FALSE;
is_new_line = TRUE;
continue;
is_new_line = TRUE;
line_len = 0;
cur_len = 0;
- do_delete = TRUE;
+ if (i_len)
+ do_delete = TRUE;
+ else
+ do_delete = FALSE;
#ifdef WRAP_DEBUG
printf("after CR insert ");
dump_text(text, line_pos, tlen, 1);
#endif
/* should we insert quotation ? */
- if (linewrap_quote && qlen) {
+ if (linewrap_quote && i_len) {
/* only if line is not already quoted */
if (!gtkut_stext_str_compare
(text, line_pos, tlen, qfmt)) {
if (line_pos - p_pos > i_len) {
ins_len = ins_quote
- (text, qlen, i_len,
- p_pos, tlen, qfmt);
+ (text, i_len, p_pos,
+ tlen, qfmt);
/* gtk_stext_compact_buffer(text); */
tlen += ins_len;
return recipient_found;
}
+static gboolean compose_check_entries(Compose *compose)
+{
+ gchar *str;
+
+ if (compose_check_for_valid_recipient(compose) == FALSE) {
+ alertpanel_error(_("Recipient is not specified."));
+ return FALSE;
+ }
+
+ str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
+ if (*str == '\0') {
+ AlertValue aval;
+
+ aval = alertpanel(_("Send"),
+ _("Subject is empty. Send it anyway?"),
+ _("Yes"), _("No"), NULL);
+ if (aval != G_ALERTDEFAULT)
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
gint compose_send(Compose *compose)
{
gint msgnum;
FolderItem *folder;
gint val;
+ if (compose_check_entries(compose) == FALSE)
+ return -1;
+
val = compose_queue(compose, &msgnum, &folder);
if (val) {
alertpanel_error(_("Could not queue message for sending"));
lock = TRUE;
- if(!compose_check_for_valid_recipient(compose)) {
- alertpanel_error(_("Recipient is not specified."));
+ if (compose_check_entries(compose) == FALSE) {
lock = FALSE;
return 1;
}
folderview_update_item
(compose->targetinfo->folder, TRUE);
}
- }
-
- /* save message to outbox */
- if (ok == 0 && prefs_common.savemsg) {
- if (compose_save_to_outbox(compose, tmp) < 0)
- alertpanel_error
- (_("Can't save the message to outbox."));
+ /* save message to outbox */
+ if (prefs_common.savemsg) {
+ Folder *folder = FOLDER(compose->account->folder);
+ FolderItem *outbox = NULL;
+
+ if (folder)
+ outbox = folder->outbox;
+ if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
+ alertpanel_error
+ (_("Can't save the message to outbox."));
+ }
}
unlink(tmp);
if (fputs(buf, fdest) == -1)
goto error;
- if (g_strncasecmp(buf, "From:", strlen("From:")) == 0) {
- fputs(" (by way of ", fdest);
- if (compose->account->name
- && *compose->account->name) {
- compose_convert_header
- (buf, sizeof(buf),
- compose->account->name,
- strlen("From: "));
- fprintf(fdest, "%s <%s>",
- buf, compose->account->address);
- } else
- fprintf(fdest, "%s",
- compose->account->address);
- fputs(")", fdest);
+ if (!prefs_common.bounce_keep_from) {
+ if (g_strncasecmp(buf, "From:",
+ strlen("From:")) == 0) {
+ fputs(" (by way of ", fdest);
+ if (compose->account->name
+ && *compose->account->name) {
+ compose_convert_header
+ (buf, sizeof(buf),
+ compose->account->name,
+ strlen("From: "));
+ fprintf(fdest, "%s <%s>",
+ buf,
+ compose->account->address);
+ } else
+ fprintf(fdest, "%s",
+ compose->account->address);
+ fputs(")", fdest);
+ }
}
if (fputs("\n", fdest) == -1)
return 0;
}
-static gint compose_save_to_outbox(Compose *compose, const gchar *file)
-{
- FolderItem *outbox;
- gchar *path;
- gint num;
- FILE *fp;
-
- debug_print(_("saving sent message...\n"));
-
- outbox = folder_get_default_outbox();
- path = folder_item_get_path(outbox);
- if (!is_dir_exist(path))
- make_dir_hier(path);
-
- folder_item_scan(outbox);
- if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
- g_free(path);
- g_warning(_("can't save message\n"));
- return -1;
- }
-
- if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
- g_warning(_("can't open mark file\n"));
- else {
- MsgInfo newmsginfo;
-
- newmsginfo.msgnum = num;
- newmsginfo.flags.perm_flags = 0;
- newmsginfo.flags.tmp_flags = 0;
- procmsg_write_flags(&newmsginfo, fp);
- fclose(fp);
- }
- g_free(path);
-
- return 0;
-}
-
static gint compose_remove_reedit_target(Compose *compose)
{
FolderItem *item;
lock = TRUE;
- if(!compose_check_for_valid_recipient(compose)) {
- alertpanel_error(_("Recipient is not specified."));
+ if (compose_check_entries(compose) == FALSE) {
lock = FALSE;
return -1;
- }
-
+ }
+
if (!compose->to_list && !compose->newsgroup_list) {
g_warning(_("can't get recipient list."));
lock = FALSE;
g_free(tmp2);
return -1;
}
-
- /* queue message */
- queue = folder_get_default_queue();
+
+ if (compose->account->folder &&
+ FOLDER(compose->account->folder)->queue)
+ queue = FOLDER(compose->account->folder)->queue;
+ else
+ queue = folder_get_default_queue();
folder_item_scan(queue);
queue_path = folder_item_get_path(queue);
menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
- tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tool/Template");
+ tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
#if 0 /* NEW COMPOSE GUI */
gtk_widget_hide(bcc_hbox);
gtk_widget_hide(bcc_entry);
}
#endif
- update_compose_actions_menu(ifactory, "/Edit/Actions", compose);
+ update_compose_actions_menu(ifactory, "/Tools/Actions", compose);
undostruct = undo_init(text);
GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
optmenu = gtk_option_menu_new();
- gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
optmenu_menu = gtk_menu_new();
MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
gtk_widget_queue_resize(compose->table_vbox);
#endif
#if USE_GPGME
- if (ac->default_sign) {
- ifactory = gtk_item_factory_from_widget(compose->menubar);
+ ifactory = gtk_item_factory_from_widget(compose->menubar);
menu_set_sensitive(ifactory,
"/Message/Sign", TRUE);
+ menu_set_sensitive(ifactory,
+ "/Message/Encrypt", TRUE);
+
menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
+ if (ac->default_sign)
gtk_check_menu_item_set_active
(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
- } else {
- ifactory = gtk_item_factory_from_widget(compose->menubar);
- menu_set_sensitive(ifactory,
- "/Message/Sign", TRUE);
- menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
+ else
gtk_check_menu_item_set_active
(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
- }
- if (ac->default_encrypt) {
- ifactory = gtk_item_factory_from_widget(compose->menubar);
- menu_set_sensitive(ifactory,
- "/Message/Encrypt", TRUE);
+
menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
+ if (ac->default_encrypt)
gtk_check_menu_item_set_active
(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
- } else {
- ifactory = gtk_item_factory_from_widget(compose->menubar);
- menu_set_sensitive(ifactory,
- "/Message/Encrypt", TRUE);
- menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
+ else
gtk_check_menu_item_set_active
(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
- }
#endif /* USE_GPGME */
}
FolderItem *draft;
gchar *tmp;
gint msgnum;
+ gchar *draft_path;
+ FILE *fp;
static gboolean lock = FALSE;
if (lock) return;
- draft = folder_get_default_draft();
+ if (compose->account && compose->account->folder &&
+ FOLDER(compose->account->folder)->draft)
+ draft = FOLDER(compose->account->folder)->draft;
+ else
+ draft = folder_get_default_draft();
g_return_if_fail(draft != NULL);
lock = TRUE;
}
folder_item_scan(draft);
- if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) <= 0) {
+ if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) < 0) {
unlink(tmp);
g_free(tmp);
lock = FALSE;
TRUE);
}
+ draft_path = folder_item_get_path(draft);
+ if ((fp = procmsg_open_mark_file(draft_path, TRUE)) == NULL)
+ g_warning(_("can't open mark file\n"));
+ else {
+ MsgInfo newmsginfo;
+
+ newmsginfo.msgnum = msgnum;
+ newmsginfo.flags.perm_flags = 0;
+ newmsginfo.flags.tmp_flags = 0;
+ procmsg_write_flags(&newmsginfo, fp);
+ fclose(fp);
+ }
+ g_free(draft_path);
+
folder_item_scan(draft);
folderview_update_item(draft, TRUE);