gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
}
-#define IS_FIRST_PART_TEXT(info) \
- ((info->type == MIMETYPE_TEXT) || \
- (info->type == MIMETYPE_MULTIPART && info->subtype && \
- !strcasecmp(info->subtype, "alternative") && \
- (info->node->children && \
- (((MimeInfo *) info->node->children->data)->type == MIMETYPE_TEXT))))
+#ifdef USE_GPGME
+static void compose_use_signing(Compose *compose, gboolean use_signing)
+{
+ GtkItemFactory *ifactory;
+ GtkWidget *menuitem = NULL;
+
+ compose->use_signing = use_signing;
+ ifactory = gtk_item_factory_from_widget(compose->menubar);
+ menuitem = gtk_item_factory_get_item
+ (ifactory, "/Message/Sign");
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
+ use_signing);
+ compose_update_gnupg_mode_menu_item(compose);
+}
+#endif /* USE_GPGME */
+
+#define NEXT_PART_NOT_CHILD(info) \
+{ \
+ node = info->node; \
+ while (node->children) \
+ node = g_node_last_child(node); \
+ info = procmime_mimeinfo_next((MimeInfo *)node->data); \
+}
static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
{
MimeInfo *mimeinfo;
MimeInfo *child;
- gchar *infile;
+ MimeInfo *firsttext = NULL;
+ MimeInfo *encrypted = NULL;
+ GNode *node;
gchar *outfile;
const gchar *partname = NULL;
mimeinfo = procmime_scan_message(msginfo);
if (!mimeinfo) return;
- /* skip first text (presumably message body) */
- child = (MimeInfo *) mimeinfo->node->children->data;
- if (!child || IS_FIRST_PART_TEXT(mimeinfo)) {
+ if (mimeinfo->node->children == NULL) {
procmime_mimeinfo_free_all(mimeinfo);
return;
}
- if (IS_FIRST_PART_TEXT(child))
- child = (MimeInfo *) child->node->next;
-
- infile = procmsg_get_message_file_path(msginfo);
-
+ /* find first content part */
+ child = (MimeInfo *) mimeinfo->node->children->data;
+ while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
+ child = (MimeInfo *)child->node->children->data;
+
+ if (child->type == MIMETYPE_TEXT) {
+ firsttext = child;
+ debug_print("First text part found\n");
+ } else if (compose->mode == COMPOSE_REEDIT &&
+ child->type == MIMETYPE_APPLICATION &&
+ !strcasecmp(child->subtype, "pgp-encrypted")) {
+ AlertValue val;
+ val = alertpanel(_("Encrypted message"),
+ _("Cannot re-edit an encrypted message. \n"
+ "Discard encrypted part?"),
+ _("Yes"), _("No"), NULL);
+ if (val == G_ALERTDEFAULT)
+ encrypted = (MimeInfo *)child->node->parent->data;
+ }
+
+ child = (MimeInfo *) mimeinfo->node->children->data;
while (child != NULL) {
- if (child->node->children || child->type == MIMETYPE_MULTIPART) {
+ if (child == encrypted) {
+ /* skip this part of tree */
+ NEXT_PART_NOT_CHILD(child);
+ continue;
+ }
+
+ if (child->type == MIMETYPE_MULTIPART) {
+ /* get the actual content */
+ child = procmime_mimeinfo_next(child);
+ continue;
+ }
+
+ if (child == firsttext) {
child = procmime_mimeinfo_next(child);
continue;
}
- if (child->node->parent && child->node->parent->parent
- && (((MimeInfo *) child->node->parent->parent->data)->type == MIMETYPE_MULTIPART)
- && !strcasecmp(((MimeInfo *) child->node->parent->parent->data)->subtype, "signed")
- && child->type == MIMETYPE_TEXT) {
- /* this is the main text part of a signed message */
+
+ if ((compose->mode == COMPOSE_REEDIT ||
+ compose->mode == COMPOSE_FORWARD_INLINE ||
+ compose->mode == COMPOSE_FORWARD ) &&
+ (child->type == MIMETYPE_APPLICATION) &&
+ !strcmp(child->subtype, "pgp-signature")) {
+#ifdef USE_GPGME
+ if (compose->mode == COMPOSE_REEDIT) {
+ compose->gnupg_mode = GNUPG_MODE_DETACH;
+ compose_use_signing(compose, TRUE);
+ }
+#endif
child = procmime_mimeinfo_next(child);
continue;
}
outfile = procmime_get_tmp_file_name(child);
if (procmime_get_part(outfile, child) < 0)
g_warning("Can't get the part of multipart message.");
- else if (compose->mode != COMPOSE_REEDIT ||
- !((child->type == MIMETYPE_APPLICATION) && !strcmp(child->subtype, "pgp-signature"))) {
+ else {
gchar *content_type;
content_type = g_strdup_printf("%s/%s", procmime_get_type_str(child->type), child->subtype);
partname = procmime_mimeinfo_get_parameter(child, "name");
-
+ if (partname == NULL)
+ partname = "";
compose_attach_append(compose, outfile,
partname, content_type);
g_free(content_type);
}
-
- child = child->node->next != NULL ? (MimeInfo *) child->node->next->data : NULL;
+ g_free(outfile);
+ NEXT_PART_NOT_CHILD(child);
}
-
- g_free(infile);
procmime_mimeinfo_free_all(mimeinfo);
}
-#undef IS_FIRST_PART_TEXT
+#undef NEXT_PART_NOT_CHILD
#define GET_CHAR(pos, buf, len) \
{ \