#include "customheader.h"
#include "prefs_common.h"
#include "prefs_account.h"
+#include "prefs_actions.h"
#include "account.h"
#include "filesel.h"
#include "procheader.h"
#include "template.h"
#include "undo.h"
#include "foldersel.h"
-#include "prefs_actions.h"
#if USE_GPGME
# include "rfc2015.h"
Compose *compose_generic_new (PrefsAccount *account,
const gchar *to,
- FolderItem *item);
+ FolderItem *item,
+ GPtrArray *attach_files);
static Compose *compose_create (PrefsAccount *account,
ComposeMode mode);
{N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
#endif /* USE_GPGME */
{N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
- {N_("/_Message/Priority"), NULL, NULL, 0, "<Branch>"},
- {N_("/_Message/Priority/Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
- {N_("/_Message/Priority/High"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
- {N_("/_Message/Priority/Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
- {N_("/_Message/Priority/Low"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
- {N_("/_Message/Priority/Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
+ {N_("/_Message/_Priority"), NULL, NULL, 0, "<Branch>"},
+ {N_("/_Message/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
+ {N_("/_Message/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
+ {N_("/_Message/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
+ {N_("/_Message/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
+ {N_("/_Message/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
{N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
{N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
{N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
{"text/uri-list", 0, 0}
};
-Compose *compose_new(PrefsAccount *account)
-{
- return compose_generic_new(account, NULL, NULL);
-}
-
Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
{
Compose *c;
gchar *filename;
GtkItemFactory *ifactory;
- c = compose_generic_new(account, NULL, NULL);
+ c = compose_generic_new(account, NULL, NULL, NULL);
filename = procmsg_get_message_file(msginfo);
if (filename == NULL)
return c;
}
-Compose *compose_new_with_recipient(PrefsAccount *account, const gchar *mailto)
+Compose *compose_new(PrefsAccount *account, const gchar *mailto,
+ GPtrArray *attach_files)
{
- return compose_generic_new(account, mailto, NULL);
+ return compose_generic_new(account, mailto, NULL, attach_files);
}
Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
{
- return compose_generic_new(account, NULL, item);
+ return compose_generic_new(account, NULL, item, NULL);
}
-Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item)
+Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
+ GPtrArray *attach_files)
{
Compose *compose;
GtkSText *text;
gtk_widget_grab_focus(compose->text);
gtkut_widget_wait_for_draw(compose->text);
-
if (account->protocol != A_NNTP) {
- if (mailto) {
+ if (mailto && *mailto != '\0') {
compose_entries_set(compose, mailto);
} else if(item && item->prefs->enable_default_to) {
*/
menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
}
+
+ if (attach_files) {
+ gint i;
+ gchar *file;
+
+ for (i = 0; i < attach_files->len; i++) {
+ file = g_ptr_array_index(attach_files, i);
+ compose_attach_append(compose, file, file, NULL);
+ }
+ }
+
compose_show_first_last_header(compose, TRUE);
/* Set save folder */
} else
reply_account = account;
- MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
- MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
- if (MSG_IS_IMAP(msginfo->flags))
- imap_msg_set_perm_flags(msginfo, MSG_REPLIED);
- CHANGE_FLAGS(msginfo);
-
compose = compose_create(account, COMPOSE_REPLY);
- compose->replyinfo = procmsg_msginfo_copy(msginfo);
+ compose->replyinfo = procmsg_msginfo_new_ref(msginfo);
#if 0 /* NEW COMPOSE GUI */
if (followup_and_reply_to) {
static void set_toolbar_style(Compose *compose);
-static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
-{
- gchar *base;
- gchar *filename;
-
- g_return_val_if_fail(mimeinfo != NULL, NULL);
-
- base = mimeinfo->filename ? mimeinfo->filename
- : mimeinfo->name ? mimeinfo->name : NULL;
-
- if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
- filename = g_strdup_printf("%s%smimetmp.%08x.html",
- get_mime_tmp_dir(),
- G_DIR_SEPARATOR_S,
- (gint)mimeinfo);
- return filename;
- }
- else {
- base = base ? base : "";
- base = g_basename(base);
- if (*base == '\0') {
- filename = g_strdup_printf("%s%smimetmp.%08x",
- get_mime_tmp_dir(),
- G_DIR_SEPARATOR_S,
- (gint)mimeinfo);
- return filename;
- }
- }
-
- filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
- base, NULL);
-
- return filename;
-}
-
-static gchar *mime_extract_file(gchar *source, MimeInfo *partinfo)
-{
- gchar *filename;
-
- if (!partinfo) return NULL;
-
- filename = procmime_get_file_name(partinfo);
-
- if (procmime_get_part(filename, source, partinfo) < 0)
- alertpanel_error
- (_("Can't get the part of multipart message."));
-
- return filename;
-}
-
-
-
#define INSERT_FW_HEADER(var, hdr) \
if (msginfo->var && *msginfo->var) { \
gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
void compose_entry_append(Compose *compose, const gchar *address,
ComposeEntryType type)
{
- GtkEntry *entry;
- const gchar *text;
gchar *header;
if (!address || *address == '\0') return;
static void compose_exec_sig(Compose *compose, gchar *sigfile)
{
- FILE *tmpfp;
- pid_t thepid;
- gchar *sigtext;
FILE *sigprg;
gchar *buf;
size_t buf_len = 128;
guint prev_line_pos, guint text_len,
gchar *quote_fmt)
{
- guint i, ins_len;
+ guint i, ins_len = 0;
gchar ch;
if (indent_len) {
/* we have encountered line break */
if (ch_len == 1 && *cbuf == '\n') {
gint clen;
- gchar cb[MB_CUR_MAX];
+ gchar cb[MB_LEN_MAX];
/* should we join the next line */
if ((i_len != cur_len) && do_delete &&
for(list = compose->header_list; list; list = list->next) {
gchar *header;
gchar *entry;
- header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
+ header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
g_strstrip(entry);
if(entry[0] != '\0') {
}
}
}
+ g_free(header);
g_free(entry);
}
return recipient_found;
}
/* write to temporary file */
- g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
- get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
+ g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
+ get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
if (prefs_common.linewrap_at_send)
compose_wrap_line_all(compose);
gchar *cc_hdr;
gchar *to_hdr;
- debug_print(_("Writing redirect header\n"));
+ debug_print("Writing redirect header\n");
cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
}
-#ifdef USE_GPGME
-/*
- * interfaces to rfc2015 to keep out the prefs stuff there.
+#if USE_GPGME
+/* interfaces to rfc2015 to keep out the prefs stuff there.
* returns 0 on success and -1 on error. */
-static int compose_create_signers_list (Compose *compose, GSList **pkey_list)
+static gint compose_create_signers_list(Compose *compose, GSList **pkey_list)
{
- const char *keyid = NULL;
+ const gchar *key_id = NULL;
GSList *key_list;
switch (compose->account->sign_key) {
case SIGN_KEY_DEFAULT:
*pkey_list = NULL;
- return 0; /* nothing to do */
-
+ return 0;
case SIGN_KEY_BY_FROM:
- keyid = compose->account->address;
+ key_id = compose->account->address;
break;
-
case SIGN_KEY_CUSTOM:
- keyid = compose->account->sign_key_id;
+ key_id = compose->account->sign_key_id;
break;
-
default:
- g_assert_not_reached ();
+ break;
}
- key_list = rfc2015_create_signers_list(keyid);
+ key_list = rfc2015_create_signers_list(key_id);
if (!key_list) {
- alertpanel_error("Could not find any key associated with currently "
- "selected keyid `%s'!", keyid);
- return -1;
+ alertpanel_error(_("Could not find any key associated with "
+ "currently selected key id `%s'."), key_id);
+ return -1;
}
-
+
*pkey_list = key_list;
return 0;
}
+
+/* clearsign message body text */
+static gint compose_clearsign_text(Compose *compose, gchar **text)
+{
+ GSList *key_list;
+ gchar *tmp_file;
+
+ tmp_file = get_tmp_file();
+ if (str_write_to_file(*text, tmp_file) < 0) {
+ g_free(tmp_file);
+ return -1;
+ }
+
+ if (canonicalize_file_replace(tmp_file) < 0 ||
+ compose_create_signers_list(compose, &key_list) < 0 ||
+ rfc2015_clearsign(tmp_file, key_list) < 0) {
+ unlink(tmp_file);
+ g_free(tmp_file);
+ return -1;
+ }
+
+ g_free(*text);
+ *text = file_read_to_str(tmp_file);
+ unlink(tmp_file);
+ g_free(tmp_file);
+ if (*text == NULL)
+ return -1;
+
+ return 0;
+}
#endif /* USE_GPGME */
static gint compose_write_to_file(Compose *compose, const gchar *file,
chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
len = strlen(chars);
if (is_ascii_str(chars)) {
- buf = g_strdup(chars);
+ buf = chars;
+ chars = NULL;
out_codeset = CS_US_ASCII;
encoding = ENC_7BIT;
} else {
unlink(file);
return -1;
} else {
- buf = g_strdup(chars);
+ buf = chars;
+ chars = NULL;
}
}
}
g_free(chars);
+#if USE_GPGME
+ if (!is_draft && compose->use_signing && compose->account->clearsign) {
+ if (compose_clearsign_text(compose, &buf) < 0) {
+ g_warning("clearsign failed\n");
+ fclose(fp);
+ unlink(file);
+ g_free(buf);
+ return -1;
+ }
+ }
+#endif
+
/* write headers */
if (compose_write_headers
(compose, fp, out_codeset, encoding, is_draft) < 0) {
for (i = 0; i < len; i += B64_LINE_SIZE) {
l = MIN(B64_LINE_SIZE, len - i);
- to64frombits(outbuf, buf + i, l);
+ base64_encode(outbuf, buf + i, l);
fputs(outbuf, fp);
fputc('\n', fp);
}
}
#if USE_GPGME
- if (compose->use_signing) {
+ if (is_draft)
+ return 0;
+
+ if ((compose->use_signing && !compose->account->clearsign) ||
+ compose->use_encryption) {
+ if (canonicalize_file_replace(file) < 0) {
+ unlink(file);
+ return -1;
+ }
+ }
+
+ if (compose->use_signing && !compose->account->clearsign) {
GSList *key_list;
-
- if (compose_create_signers_list(compose, &key_list) == -1 ||
- rfc2015_sign(file, key_list) < 0) {
-
+
+ if (compose_create_signers_list(compose, &key_list) < 0 ||
+ rfc2015_sign(file, key_list) < 0) {
unlink(file);
return -1;
}
}
if (compose->use_encryption) {
- if (rfc2015_encrypt(file, compose->to_list, compose->account->ascii_armored) < 0) {
+ if (rfc2015_encrypt(file, compose->to_list,
+ compose->account->ascii_armored) < 0) {
unlink(file);
return -1;
}
GSList *cur;
gchar buf[BUFFSIZE];
gint num;
- MsgFlags flag = {0, 0};
static gboolean lock = FALSE;
PrefsAccount *mailac = NULL, *newsac = NULL;
- debug_print(_("queueing message...\n"));
+ debug_print("queueing message...\n");
g_return_val_if_fail(compose->account != NULL, -1);
g_return_val_if_fail(compose->orig_account != NULL, -1);
}
/* Save copy folder */
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
- gchar *str;
+ gchar *savefolderid;
- str = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
- fprintf(fp, "SCF:%s\n", str);
- g_free(str);
+ savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
+ fprintf(fp, "SCF:%s\n", savefolderid);
+ g_free(savefolderid);
+ }
+ /* Message-ID of message replying to */
+ if((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
+ gchar *folderid;
+
+ folderid = folder_item_get_identifier(compose->replyinfo->folder);
+ fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
+ g_free(folderid);
}
fprintf(fp, "\n");
while ((len = fread(inbuf, sizeof(gchar),
B64_LINE_SIZE, attach_fp))
== B64_LINE_SIZE) {
- to64frombits(outbuf, inbuf, B64_LINE_SIZE);
+ base64_encode(outbuf, inbuf, B64_LINE_SIZE);
fputs(outbuf, fp);
fputc('\n', fp);
}
if (len > 0 && feof(attach_fp)) {
- to64frombits(outbuf, inbuf, len);
+ base64_encode(outbuf, inbuf, len);
fputs(outbuf, fp);
fputc('\n', fp);
}
#define QUOTE_IF_REQUIRED(out, str) \
{ \
- if (*str != '"' && strchr(str, ',')) { \
+ if (*str != '"' && (strchr(str, ',') \
+ || strchr(str, '.'))) { \
gchar *__tmp; \
gint len; \
\
return 0;
}
- debug_print(_("Writing %s-header\n"), header);
+ debug_print("Writing %s-header\n", header);
header_w_colon = g_strconcat(header, ":", NULL);
trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
case PRIORITY_LOWEST: fprintf(fp, "Importance: low\n"
"X-Priority: 5 (Lowest)\n");
break;
- default: debug_print(_("compose: priority unknown : %d\n"),
+ default: debug_print("compose: priority unknown : %d\n",
compose->priority);
}
lt->tm_min, lt->tm_sec,
(guint)random(), addr);
- debug_print(_("generated Message-ID: %s\n"), buf);
+ debug_print("generated Message-ID: %s\n", buf);
g_free(addr);
}
-static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
- GtkWidget **entry, gint *count,
- const gchar *label_str,
- gboolean is_addr_entry)
-{
- GtkWidget *label;
-
- if (GTK_TABLE(table)->nrows < (*count) + 1)
- gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
-
- *hbox = gtk_hbox_new(FALSE, 0);
- label = gtk_label_new
- (prefs_common.trans_hdr ? gettext(label_str) : label_str);
- gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
- gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
- GTK_FILL, 0, 2, 0);
- *entry = gtk_entry_new_with_max_length(MAX_ENTRY_LENGTH);
- gtk_table_attach
- (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
-#if 0 /* NEW COMPOSE GUI */
- if (GTK_TABLE(table)->nrows > (*count) + 1)
- gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
-#endif
-
- if (is_addr_entry)
- address_completion_register_entry(GTK_ENTRY(*entry));
-
- (*count)++;
-}
-
static void compose_create_header_entry(Compose *compose)
{
gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
GtkWidget *scrolledwin;
GtkWidget *text;
- GtkWidget *table;
-
UndoMain *undostruct;
gchar *titles[N_ATTACH_COLS];
g_return_val_if_fail(account != NULL, NULL);
- debug_print(_("Creating compose window...\n"));
+ debug_print("Creating compose window...\n");
compose = g_new0(Compose, 1);
titles[COL_MIMETYPE] = _("MIME type");
GtkWidget *menuitem;
if (!gtkpspell_set_sug_mode(gtkpspell, prefs_common.pspell_sugmode)) {
- debug_print(_("Pspell: could not set suggestion mode %s"),
+ debug_print("Pspell: could not set suggestion mode %s\n",
gtkpspellcheckers->error_message);
gtkpspell_checkers_reset_error();
}
static void compose_update_priority_menu_item(Compose * compose)
{
GtkItemFactory *ifactory;
- GtkWidget *menuitem;
+ GtkWidget *menuitem = NULL;
ifactory = gtk_item_factory_from_widget(compose->menubar);
static void compose_exec_ext_editor(Compose *compose)
{
- gchar tmp[64];
+ gchar *tmp;
pid_t pid;
gint pipe_fds[2];
- g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
- g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
+ tmp = g_strdup_printf("%s%ctmpmsg.%08x", get_tmp_dir(),
+ G_DIR_SEPARATOR, (gint)compose);
if (pipe(pipe_fds) < 0) {
perror("pipe");
+ g_free(tmp);
return;
}
if ((pid = fork()) < 0) {
perror("fork");
+ g_free(tmp);
return;
}
close(pipe_fds[1]);
_exit(0);
}
+
+ g_free(tmp);
}
static gint compose_exec_ext_editor_real(const gchar *file)
Compose *compose = (Compose *)data;
gint i = 0;
- debug_print(_("Compose: input from monitoring process\n"));
+ debug_print("Compose: input from monitoring process\n");
gdk_input_remove(compose->exteditor_tag);
FolderItem *draft;
gchar *tmp;
gint msgnum;
- MsgFlags flag = {0, 0};
static gboolean lock = FALSE;
MsgInfo *newmsginfo;
lock = TRUE;
- tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
+ tmp = g_strdup_printf("%s%cdraft.%08x", get_tmp_dir(),
G_DIR_SEPARATOR, (gint)compose);
if (compose_write_to_file(compose, tmp, TRUE) < 0) {
(GTK_EDITABLE(compose->focused_editable), 0, -1);
}
-static void compose_move_beginning_of_line_cb(Compose *compose)
-{
- if (compose->focused_editable &&
- GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
- gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
-}
-
static void compose_gtk_stext_action_cb(Compose *compose, ComposeCallGtkSTextAction action)
{
if (!(compose->focused_editable && GTK_WIDGET_HAS_FOCUS(compose->focused_editable))) return;