#include "gtkutils.h"
#include "stock_pixmap.h"
#include "filesel.h"
-#include "manage_window.h"
#include "alertpanel.h"
#include "inputdialog.h"
#include "statusbar.h"
gconstpointer ptr1,
gconstpointer ptr2);
+static void news_process_crossposted (MsgInfo *msginfo);
+static void news_flag_crosspost (MsgInfo *msginfo);
+
GtkTargetEntry summary_drag_types[1] =
{
{"text/plain", GTK_TARGET_SAME_APP, TARGET_DUMMY}
{N_("/---"), NULL, NULL, 0, "<Separator>"},
{N_("/Re-_edit"), NULL, summary_reedit, 0, NULL},
{N_("/---"), NULL, NULL, 0, "<Separator>"},
+ {N_("/Select _thread"), NULL, summary_select_thread, 0, NULL},
+ {N_("/Select _all"), NULL, summary_select_all, 0, NULL},
+ {N_("/---"), NULL, NULL, 0, "<Separator>"},
{N_("/M_ove..."), NULL, summary_move_to, 0, NULL},
{N_("/_Copy..."), NULL, summary_copy_to, 0, NULL},
{N_("/_Delete"), NULL, summary_delete, 0, NULL},
{N_("/---"), NULL, NULL, 0, "<Separator>"},
{N_("/_Save as..."), NULL, summary_save_as, 0, NULL},
{N_("/_Print..."), NULL, summary_print, 0, NULL},
- {N_("/---"), NULL, NULL, 0, "<Separator>"},
- {N_("/Select _all"), NULL, summary_select_all, 0, NULL}
};
static const gchar *const col_label[N_SUMMARY_COLS] = {
node = summary_find_next_unread_msg(summaryview, NULL);
if (node == NULL && GTK_CLIST(ctree)->row_list != NULL)
node = gtk_ctree_node_nth
- (ctree, GTK_CLIST(ctree)->rows - 1);
+ (ctree, sort_type ==
+ GTK_SORT_DESCENDING ? 0 :
+ GTK_CLIST(ctree)->rows - 1);
summary_select_node(summaryview, node, FALSE, TRUE);
}
} else {
if (node == NULL && GTK_CLIST(ctree)->row_list != NULL) {
/* Get the last visible node on screen */
/* FIXME: huh, what happens if node is null? that allowed?? */
- node = gtk_ctree_node_nth(ctree, GTK_CLIST(ctree)->rows - 1);
+ node = gtk_ctree_node_nth(ctree, sort_type ==
+ GTK_SORT_DESCENDING ? 0 :
+ GTK_CLIST(ctree)->rows - 1);
}
if (prefs_common.open_unread_on_enter) {
summary_unlock(summaryview);
return;
}
- if (summaryview->folder_item->folder->type != F_NEWS) {
+ if (summaryview->folder_item->folder->type != F_NEWS)
menu_set_sensitive(ifactory, "/Move...", TRUE);
- menu_set_sensitive(ifactory, "/Delete", TRUE);
- }
+ else
+ menu_set_sensitive(ifactory, "/Move...", FALSE);
+ menu_set_sensitive(ifactory, "/Delete", TRUE);
+ menu_set_sensitive(ifactory, "/Select thread", TRUE);
+ menu_set_sensitive(ifactory, "/Select all", TRUE);
menu_set_sensitive(ifactory, "/Copy...", TRUE);
menu_set_sensitive(ifactory, "/Execute", TRUE);
summaryview->folder_item->stype == F_DRAFT ||
summaryview->folder_item->stype == F_QUEUE)
menu_set_sensitive(ifactory, "/Re-edit", sens);
+ else
+ menu_set_sensitive(ifactory, "/Re-edit", FALSE);
menu_set_sensitive(ifactory, "/Save as...", sens);
menu_set_sensitive(ifactory, "/Print...", TRUE);
- menu_set_sensitive(ifactory, "/Select all", TRUE);
-
if (summaryview->folder_item->folder->account)
sens = summaryview->folder_item->folder->account->protocol
== A_NNTP;
msginfo = gtk_ctree_node_get_row_data(ctree, node);
+ if (MSG_IS_NEWS(msginfo->flags))
+ news_flag_crosspost(msginfo);
+
if (MSG_IS_NEW(msginfo->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags))
summaryview->newmsgs++;
if (MSG_IS_UNREAD(msginfo->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags))
n_selected++;
}
- gtk_label_set(GTK_LABEL(summaryview->statlabel_folder),
- summaryview->folder_item &&
- summaryview->folder_item->folder->type == F_NEWS
- ? g_basename(summaryview->folder_item->path)
- : summaryview->folder_item->path);
+ if (summaryview->folder_item->folder->type == F_NEWS) {
+ gchar *group;
+ group = get_abbrev_newsgroup_name
+ (g_basename(summaryview->folder_item->path));
+ gtk_label_set(GTK_LABEL(summaryview->statlabel_folder), group);
+ g_free(group);
+ } else {
+ gtk_label_set(GTK_LABEL(summaryview->statlabel_folder),
+ summaryview->folder_item->path);
+ }
if (summaryview->deleted)
del = g_strdup_printf(_("%d deleted"), summaryview->deleted);
GTKUT_CTREE_NODE_SET_ROW_DATA(cnode, msginfo);
summary_set_marks_func(ctree, cnode, summaryview);
- if (msgid)
+ if (msgid && msgid[0] != '\0')
g_hash_table_insert(msgid_table, (gchar *)msgid, cnode);
return TRUE;
GTKUT_CTREE_NODE_SET_ROW_DATA(node, msginfo);
summary_set_marks_func(ctree, node, summaryview);
- if (msginfo->msgid)
+ if (msginfo->msgid && msginfo->msgid[0] != '\0')
g_hash_table_insert(msgid_table,
msginfo->msgid, node);
cachefile = folder_item_get_cache_file(summaryview->folder_item);
g_return_val_if_fail(cachefile != NULL, -1);
- if ((fps.cache_fp = fopen(cachefile, "w")) == NULL) {
+ if ((fps.cache_fp = fopen(cachefile, "wb")) == NULL) {
FILE_OP_ERROR(cachefile, "fopen");
g_free(cachefile);
return -1;
g_free(cachefile);
markfile = folder_item_get_mark_file(summaryview->folder_item);
- if ((fps.mark_fp = fopen(markfile, "w")) == NULL) {
+ if ((fps.mark_fp = fopen(markfile, "wb")) == NULL) {
FILE_OP_ERROR(markfile, "fopen");
fclose(fps.cache_fp);
g_free(markfile);
procmsg_write_flags(msginfo, fps->mark_fp);
}
+static gchar *summary_complete_address(const gchar *addr)
+{
+ gint count;
+ gchar *res, *tmp, *email_addr;
+
+ Xstrdup_a(email_addr, addr, return NULL);
+ extract_address(email_addr);
+ g_return_val_if_fail(*email_addr, NULL);
+
+ /*
+ * completion stuff must be already initialized
+ */
+ res = NULL;
+ if (1 < (count = complete_address(email_addr))) {
+ tmp = get_complete_address(1);
+ res = procheader_get_fromname(tmp);
+ g_free(tmp);
+ }
+
+ return res;
+}
+
static void summary_set_header(SummaryView *summaryview, gchar *text[],
MsgInfo *msginfo)
{
_("(No From)");
if (prefs_common.swap_from && msginfo->from && msginfo->to &&
!MSG_IS_NEWS(msginfo->flags)) {
- gchar *from;
+ gchar *addr = NULL;
- Xstrdup_a(from, msginfo->from, return);
- extract_address(from);
- if (account_find_from_address(from)) {
+ if (prefs_common.use_addr_book) {
+ Xstrdup_a(addr, msginfo->from, return);
+ extract_address(addr);
+ }
+
+ if (account_find_from_address(addr)) {
+ addr = summary_complete_address(msginfo->to);
g_free(to);
- to = g_strconcat("-->", msginfo->to, NULL);
+ to = g_strconcat("-->", addr == NULL ? msginfo->to : addr, NULL);
text[col_pos[S_COL_FROM]] = to;
}
}
- if ((text[col_pos[S_COL_FROM]] != to) && prefs_common.use_addr_book &&
- msginfo->from) {
- gint count;
+ /*
+ * CLAWS: note that the "text[col_pos[S_COL_FROM]] != to" is really a hack,
+ * checking whether the above block (which handles the special case of
+ * the --> in sent boxes) was executed.
+ */
+ if (text[col_pos[S_COL_FROM]] != to && prefs_common.use_addr_book && msginfo->from) {
gchar *from;
-
- Xstrdup_a(from, msginfo->from, return);
- extract_address(from);
- if (*from) {
- count = complete_address(from);
- if (count > 1) {
- g_free(from_name);
- from = get_complete_address(1);
- from_name = procheader_get_fromname(from);
- g_free(from);
- text[col_pos[S_COL_FROM]] = from_name;
- }
- }
+ from = summary_complete_address(msginfo->from);
+ if (from) {
+ /*
+ * FIXME: this text[col_pos[S_COL_FROM]] should be freed
+ * but may have been assigned _("No From"). Should be
+ * freed???
+ */
+ text[col_pos[S_COL_FROM]] = from;
+ }
}
if (prefs->enable_simplify_subject
messageview_show(msgview, msginfo, all_headers);
if (msgview->type == MVIEW_TEXT ||
(msgview->type == MVIEW_MIME &&
- GTK_CLIST(msgview->mimeview->ctree)->row_list == NULL))
+ (GTK_CLIST(msgview->mimeview->ctree)->row_list == NULL ||
+ gtk_notebook_get_current_page
+ (GTK_NOTEBOOK(msgview->mimeview->notebook)) == 0)))
gtk_widget_grab_focus(summaryview->ctree);
GTK_EVENTS_FLUSH();
gtkut_ctree_node_move_if_on_the_edge(ctree, row);
summary_status_show(summaryview);
}
+static gboolean check_permission(SummaryView *summaryview, MsgInfo * msginfo)
+{
+ GList * cur;
+ gboolean found;
+
+ switch (summaryview->folder_item->folder->type) {
+
+ case F_NEWS:
+
+ /*
+ security : checks if one the accounts correspond to
+ the author of the post
+ */
+
+ found = FALSE;
+ for(cur = account_get_list() ; cur != NULL ; cur = cur->next) {
+ PrefsAccount * account;
+ gchar * from_name;
+
+ account = cur->data;
+ if (account->name && *account->name)
+ from_name =
+ g_strdup_printf("%s <%s>",
+ account->name,
+ account->address);
+ else
+ from_name =
+ g_strdup_printf("%s",
+ account->address);
+
+ if (g_strcasecmp(from_name, msginfo->from) == 0) {
+ g_free(from_name);
+ found = TRUE;
+ break;
+ }
+ g_free(from_name);
+ }
+
+ if (!found) {
+ alertpanel_error(_("You're not the author of the article\n"));
+ }
+
+ return found;
+
+ default:
+ return TRUE;
+ }
+}
+
static void summary_delete_row(SummaryView *summaryview, GtkCTreeNode *row)
{
gboolean changed = FALSE;
msginfo = gtk_ctree_node_get_row_data(ctree, row);
+ if (!check_permission(summaryview, msginfo))
+ return;
+
if (MSG_IS_LOCKED(msginfo->flags)) return;
if (MSG_IS_DELETED(msginfo->flags)) return;
GtkCTreeNode *sel_last = NULL;
GtkCTreeNode *node;
+ if (!item) return;
+#if 0
if (!item || item->folder->type == F_NEWS) return;
+#endif
if (summary_is_locked(summaryview)) return;
}
src = procmsg_get_message_file(msginfo);
- copy_file(src, dest);
+ if (copy_file(src, dest) < 0) {
+ alertpanel_error(_("Can't save the file `%s'."),
+ g_basename(dest));
+ }
g_free(src);
}
GSList *cur;
trash = summaryview->folder_item->folder->trash;
+
if (summaryview->folder_item->folder->type == F_MH) {
g_return_if_fail(trash != NULL);
}
if (!summaryview->mlist) return;
- if (summaryview->folder_item != trash)
- folder_item_move_msgs_with_dest(trash, summaryview->mlist);
+ if (trash == NULL || summaryview->folder_item == trash)
+ folder_item_remove_msgs(summaryview->folder_item,
+ summaryview->mlist);
else
- folder_item_remove_msgs(trash, summaryview->mlist);
+ folder_item_move_msgs_with_dest(trash, summaryview->mlist);
for (cur = summaryview->mlist; cur != NULL; cur = cur->next)
procmsg_msginfo_free((MsgInfo *)cur->data);
g_slist_free(summaryview->mlist);
summaryview->mlist = NULL;
- if (summaryview->folder_item != trash) {
+ if ((summaryview->folder_item != trash) && (trash != NULL)) {
folder_item_scan(trash);
folderview_update_item(trash, FALSE);
}
MsgInfo * msginfo;
msginfo = (MsgInfo *) cur->data;
- filter_msginfo_move_or_delete(processing_list, msginfo,
- summaryview->folder_table);
+ filter_message_by_msginfo(processing_list, msginfo,
+ summaryview->folder_table);
}
folder_item_scan_foreach(summaryview->folder_table);
* we want the lock to be context aware...
*/
if (global_processing) {
- /*
- * CLAWS: to prevent summary_show to write the cache,
- * we force an update of the summaryview in a special way,
- * like inc.c::inc_finished().
- */
- folderview_unselect(summaryview->folderview);
- folderview_select(summaryview->folderview, summaryview->folder_item);
+ summary_show(summaryview, summaryview->folder_item, TRUE);
}
}
if (dest && strcmp2(dest->path, FILTER_NOT_RECEIVE) != 0 &&
summaryview->folder_item != dest)
summary_move_row_to(summaryview, node, dest);
- }
- else
- filter_msginfo_move_or_delete(global_processing, msginfo,
- summaryview->folder_table);
+ } else
+ filter_message_by_msginfo(global_processing, msginfo, summaryview->folder_table);
}
void summary_filter_open(SummaryView *summaryview, PrefsFilterType type)
{
- static HeaderEntry hentry[] = {{"List-Id:", NULL, FALSE},
+ static HeaderEntry hentry[] = {{"X-BeenThere:", NULL, FALSE},
{"X-ML-Name:", NULL, FALSE},
{"X-List:", NULL, FALSE},
{"X-Mailing-list:", NULL, FALSE},
+ {"List-Id:", NULL, FALSE},
{NULL, NULL, FALSE}};
+
+ static gchar *header_strs[] = {"From", "from", "To", "to", "Subject", "subject"};
+
+ static gchar *hentry_strs[] = {"X-BeenThere", "X-ML-Name", "X-List",
+ "X-Mailing-List", "List-Id",
+ "header \"X-BeenThere\"", "header \"X-ML-Name\"",
+ "header \"X-List\"", "header \"X-Mailing-List\"",
+ "header \"List-Id\""};
enum
{
- H_LIST_ID = 0,
+ H_X_BEENTHERE = 0,
H_X_ML_NAME = 1,
H_X_LIST = 2,
- H_X_MAILING_LIST = 3
+ H_X_MAILING_LIST = 3,
+ H_LIST_ID = 4
+ };
+
+ enum
+ {
+ H_FROM = 0,
+ H_TO = 2,
+ H_SUBJECT = 4
};
MsgInfo *msginfo;
gchar *header = NULL;
gchar *key = NULL;
FILE *fp;
+ int header_offset;
+ int hentry_offset;
if (!summaryview->selected) return;
summaryview->selected);
if (!msginfo) return;
+ if (global_processing) {
+ header_offset = 1;
+ hentry_offset = 5;
+ }
+ else {
+ header_offset = 0;
+ hentry_offset = 0;
+ }
+
switch (type) {
case FILTER_BY_NONE:
break;
procheader_get_header_fields(fp, hentry);
fclose(fp);
- if (hentry[H_LIST_ID].body != NULL) {
- header = "List-Id";
- Xstrdup_a(key, hentry[H_LIST_ID].body, );
+ if (hentry[H_X_BEENTHERE].body != NULL) {
+ header = hentry_strs[H_X_BEENTHERE + hentry_offset];
+ Xstrdup_a(key, hentry[H_X_BEENTHERE].body, );
} else if (hentry[H_X_ML_NAME].body != NULL) {
- header = "X-ML-Name";
+ header = hentry_strs[H_X_ML_NAME + hentry_offset];
Xstrdup_a(key, hentry[H_X_ML_NAME].body, );
} else if (hentry[H_X_LIST].body != NULL) {
- header = "X-List";
+ header = hentry_strs[H_X_LIST + hentry_offset];
Xstrdup_a(key, hentry[H_X_LIST].body, );
} else if (hentry[H_X_MAILING_LIST].body != NULL) {
- header = "X-Mailing-list";
+ header = hentry_strs[H_X_MAILING_LIST + hentry_offset];
Xstrdup_a(key, hentry[H_X_MAILING_LIST].body, );
+ } else if (hentry[H_LIST_ID].body != NULL) {
+ header = hentry_strs[H_LIST_ID + hentry_offset];
+ Xstrdup_a(key, hentry[H_LIST_ID].body, );
} else if (msginfo->subject) {
- header = "Subject";
+ header = header_strs[H_SUBJECT + header_offset];
key = msginfo->subject;
}
- g_free(hentry[H_LIST_ID].body);
- hentry[H_LIST_ID].body = NULL;
+ g_free(hentry[H_X_BEENTHERE].body);
+ hentry[H_X_BEENTHERE].body = NULL;
g_free(hentry[H_X_ML_NAME].body);
hentry[H_X_ML_NAME].body = NULL;
g_free(hentry[H_X_LIST].body);
hentry[H_X_LIST].body = NULL;
g_free(hentry[H_X_MAILING_LIST].body);
hentry[H_X_MAILING_LIST].body = NULL;
+ g_free(hentry[H_LIST_ID].body);
+ hentry[H_LIST_ID].body = NULL;
break;
case FILTER_BY_FROM:
- header = "From";
+ header = header_strs[H_FROM + header_offset];
key = msginfo->from;
break;
case FILTER_BY_TO:
- header = "To";
+ header = header_strs[H_TO + header_offset];
key = msginfo->to;
break;
case FILTER_BY_SUBJECT:
- header = "Subject";
+ header = header_strs[H_SUBJECT + header_offset];
key = msginfo->subject;
break;
default:
break;
}
- prefs_filter_open(header, key);
+ if (global_processing)
+ prefs_filtering_open(NULL, header, key);
+ else
+ prefs_filter_open(header, key);
}
void summary_reply(SummaryView *summaryview, ComposeMode mode)
}
+
/* callback functions */
static void summary_toggle_view_cb(GtkWidget *button,
return MSG_GET_COLORLABEL(msginfo1->flags) -
MSG_GET_COLORLABEL(msginfo2->flags);
}
+
+static void news_flag_crosspost(MsgInfo *msginfo)
+{
+ GString *line;
+ gpointer key;
+ gpointer value;
+ MsgPermFlags flags;
+ Folder *mff = msginfo->folder->folder;
+
+ if (mff->account->mark_crosspost_read && MSG_IS_NEWS(msginfo->flags)) {
+ line = g_string_sized_new(128);
+ g_string_sprintf(line, "%s:%d", msginfo->folder->path, msginfo->msgnum);
+ debug_print(_("nfcp: checking <%s>"), line->str);
+ if (mff->newsart &&
+ g_hash_table_lookup_extended(mff->newsart, line->str, &key, &value)) {
+ debug_print(_(" <%s>"), value);
+ if (MSG_IS_NEW(msginfo->flags) || MSG_IS_UNREAD(msginfo->flags)) {
+ MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_NEW | MSG_UNREAD);
+ MSG_SET_COLORLABEL_VALUE(msginfo->flags, mff->account->crosspost_col);
+ }
+ g_hash_table_remove(mff->newsart, key);
+ g_free(key);
+ }
+ g_string_free(line, TRUE);
+ debug_print(_("\n"));
+ }
+}
+
+static void news_process_crossposted(MsgInfo *msginfo)
+{
+ gchar **crossref;
+ gchar **crp;
+ gchar *cp;
+ gint cnt;
+ static char *read = "read";
+ Folder *mff = msginfo->folder->folder;
+
+ /* Get the Xref: line */
+ if (msginfo->xref) {
+ /* Retrieve the cross-posted groups and message ids */
+ /* Format of Xref is Xref: server message:id message:id ... */
+ crossref = g_strsplit(msginfo->xref, " ", 1024);
+ for (crp = crossref+2, cnt = 0; *crp; crp++, cnt++) {
+ if ((cp = strchr(*crp, ':'))) {
+ *cp = '\0';
+ if (!strcmp(*crp, msginfo->folder->path)) continue;
+ *cp = ':';
+
+ /* On first pass, create a GHashTable to hold the list of
+ * article numbers per newsgroup that have been read. */
+ if (!mff->newsart) {
+ mff->newsart = g_hash_table_new(g_str_hash, g_str_equal);
+ }
+ /* When a summary is selected, the articles for that
+ * newsgroup are marked based on this entry */
+ g_hash_table_insert(mff->newsart, g_strdup(*crp), read);
+ debug_print(_("Cross-reference %d: Hash <%s>\n"), cnt, *crp);
+ }
+ }
+ g_strfreev(crossref);
+ }
+}
+
static gint summary_cmp_by_score(GtkCList *clist,
gconstpointer ptr1, gconstpointer ptr2)
{
return MSG_IS_LOCKED(msginfo1->flags) - MSG_IS_LOCKED(msginfo2->flags);
}
+static void summary_select_thread_func(GtkCTree *ctree, GtkCTreeNode *row, gpointer data)
+{
+ SummaryView *summaryview = (SummaryView *) data;
+ MsgInfo *msginfo;
+
+ msginfo = gtk_ctree_node_get_row_data(ctree, row);
+ gtk_ctree_select(GTK_CTREE(ctree), row);
+ debug_print(_("Message %d selected\n"),
+ msginfo->msgnum);
+}
+
+/* select current thread */
+void summary_select_thread(SummaryView *summaryview)
+{
+ GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
+ GtkCTreeNode *node = summaryview->selected;
+ GList *cur;
+
+ while (GTK_CTREE_ROW(node)->parent != NULL)
+ node = GTK_CTREE_ROW(node)->parent;
+
+ if (node && node != summaryview->selected)
+ summary_select_node(summaryview, node, TRUE, FALSE);
+
+ for (cur = GTK_CLIST(ctree)->selection; cur != NULL; cur = cur->next) {
+ gtk_ctree_pre_recursive(ctree, GTK_CTREE_NODE(cur->data), GTK_CTREE_FUNC(summary_select_thread_func), summaryview);
+ }
+
+ summary_status_show(summaryview);
+}
+
static void summary_ignore_thread_func(GtkCTree *ctree, GtkCTreeNode *row, gpointer data)
{
SummaryView *summaryview = (SummaryView *) data;
msginfo->msgnum);
}
+
static void summary_ignore_thread(SummaryView *summaryview)
{
GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
summary_status_show(summaryview);
}
-
static gboolean processing_apply_func(GNode *node, gpointer data)
{
FolderItem *item;
MsgInfo * msginfo;
msginfo = (MsgInfo *) cur->data;
- filter_msginfo_move_or_delete(processing, msginfo,
- NULL);
+ filter_message_by_msginfo(processing, msginfo, NULL);
procmsg_msginfo_free(msginfo);
}
gtk_widget_show(pixmap);
summaryview->folder_pixmap = pixmap;
+ summary_write_cache(summaryview);
+
folderview_unselect(summaryview->folderview);
folderview_select(summaryview->folderview, summaryview->folder_item);
}