[Commits] att_remover.c 1.1.2.26 1.1.2.27
pawel at claws-mail.org
pawel at claws-mail.org
Mon Dec 5 16:12:31 CET 2011
Update of /home/claws-mail/plugins/att_remover/src
In directory claws-mail:/tmp/cvs-serv15652/src
Modified Files:
Tag: gtk2
att_remover.c
Log Message:
2011-12-05 [pawel] 1.0.12cvs1
* commitHelper
Support bash not in /bin
* src/att_remover.c
Split removal of attachments to 2 phases, first remove
selected attachments and in second phase remove uneeded
multipart leftovers. This allows us to avoid crashers and
leave more sane MIME structure afterwards.
Fixes bug #2555 'att_remover plugin crash case'
Index: att_remover.c
===================================================================
RCS file: /home/claws-mail/plugins/att_remover/src/Attic/att_remover.c,v
retrieving revision 1.1.2.26
retrieving revision 1.1.2.27
diff -u -d -r1.1.2.26 -r1.1.2.27
--- att_remover.c 19 Jan 2010 17:37:31 -0000 1.1.2.26
+++ att_remover.c 5 Dec 2011 15:12:29 -0000 1.1.2.27
@@ -152,7 +152,7 @@
GtkTreeModel *model = attremover->model;
GtkTreeIter iter;
MsgInfo *newmsg;
- MimeInfo *info, *parent, *gparent, *partinfo;
+ MimeInfo *info, *parent, *last, *partinfo;
GNode *child;
gint att_all = 0, att_removed = 0, msgnum;
gboolean to_removal, iter_valid=TRUE;
@@ -160,7 +160,7 @@
newmsg = procmsg_msginfo_copy(attremover->msginfo);
info = procmime_scan_message(newmsg);
- partinfo = find_first_text_part(info);
+ last = partinfo = find_first_text_part(info);
partinfo = procmime_mimeinfo_next(partinfo);
if (!partinfo || !gtk_tree_model_get_iter_first(model, &iter)) {
gtk_widget_destroy(attremover->window);
@@ -175,6 +175,7 @@
while (partinfo && iter_valid) {
if (partinfo->type == MIMETYPE_MULTIPART) {
+ last = partinfo;
partinfo = procmime_mimeinfo_next(partinfo);
continue;
}
@@ -183,62 +184,52 @@
gtk_tree_model_get(model, &iter, ATT_REMOVER_TOGGLE,
&to_removal, -1);
if (!to_removal) {
+ last = partinfo;
partinfo = procmime_mimeinfo_next(partinfo);
iter_valid = gtk_tree_model_iter_next(model, &iter);
continue;
}
-
- parent = (MimeInfo *) partinfo->node->parent->data;
- gparent = (MimeInfo *) parent->node->parent->data;
- /* multipart/{alternative,mixed,related} make sense
- only when they have at least 2 nodes, remove them
- and move their nodes one level up if otherwise */
- if ((!strcmp(parent->subtype, "alternative") &&
- g_node_n_children(parent->node) <= 2) ||
- (!strcmp(parent->subtype, "mixed") &&
- g_node_n_children(parent->node) <= 2) ||
- (!strcmp(parent->subtype, "related") &&
- g_node_n_children(parent->node) <= 2) ||
- !strcmp(parent->subtype, "signed"))
- {
- while((child = g_node_last_child(parent->node)) != NULL) {
- g_node_unlink(child);
- g_node_prepend(gparent->node, child);
- }
-
- g_node_unlink(parent->node);
- g_node_destroy(parent->node);
- }
-
parent = partinfo;
partinfo = procmime_mimeinfo_next(partinfo);
iter_valid = gtk_tree_model_iter_next(model, &iter);
- g_node_unlink(parent->node);
g_node_destroy(parent->node);
att_removed++;
}
- partinfo = find_first_text_part(info);
- if (strcmp(partinfo->subtype, "plain") && partinfo->node->next) {
- parent = partinfo;
- while (1) {
- if (!strcmp(parent->subtype, "plain")) {
- partinfo = parent;
- break;
+ partinfo = last;
+ while (partinfo) {
+ if (!(parent = procmime_mimeinfo_parent(partinfo)))
+ break;
+
+ /* multipart/{alternative,mixed,related} make sense
+ only when they have at least 2 nodes, remove last
+ one and move it one level up if otherwise */
+ if (partinfo->type == MIMETYPE_MULTIPART &&
+ g_node_n_children(partinfo->node) < 2)
+ {
+ gint pos = g_node_child_position(parent->node, partinfo->node);
+ g_node_unlink(partinfo->node);
+
+ if ((child = g_node_first_child(partinfo->node))) {
+ g_node_unlink(child);
+ g_node_insert(parent->node, pos, child);
}
- if (parent->node->next)
- parent = (MimeInfo *) parent->node->next->data;
- else
- break;
+ g_node_destroy(partinfo->node);
+
+ child = g_node_last_child(parent->node);
+ partinfo = child ? child->data : parent;
}
- }
-
- if (partinfo->node->prev) {
- parent = (MimeInfo *) partinfo->node->parent->data;
- g_node_unlink(partinfo->node);
- g_node_prepend(parent->node, partinfo->node);
+
+ if (partinfo->node->prev) {
+ partinfo = (MimeInfo *) partinfo->node->prev->data;
+ if (partinfo->node->children) {
+ child = g_node_last_child(partinfo->node);
+ partinfo = (MimeInfo *) child->data;
+ }
+ } else if (partinfo->node->parent)
+ partinfo = (MimeInfo *) partinfo->node->parent->data;
}
msgnum = save_new_message(attremover->msginfo, newmsg, info,
More information about the Commits
mailing list