cancel news is finally implemented
authorHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Fri, 1 Mar 2002 20:27:37 +0000 (20:27 +0000)
committerHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Fri, 1 Mar 2002 20:27:37 +0000 (20:27 +0000)
ChangeLog.claws
configure.in
src/mainwindow.c
src/news.c
src/news.h
src/summaryview.c

index 613cf64..2a5180f 100644 (file)
@@ -1,3 +1,20 @@
+2002-03-01 [hoa]       0.7.2claws23
+
+       * src/mainwindow.c
+               Set sensitivity of delete actions to active
+               even if the folder is a newsgroup.
+
+       * src/summaryview.c
+               - Set sensitivity of delete actions
+               - Added function check_permission() that will check if the
+                 user is authorized to delete a message. For news, it
+                 will check if the author is the same.
+               - Enabled deletion when there is no trash folder.
+
+       * src/news.[ch]
+               - Added news_cancel_article() to cancel articles
+               - Implemented news_remove_message() (public function)
+
 2002-03-01 [paul]      0.7.2claws22
 
        * src/gtkutils.c
index 8c52f9d..9783441 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=7
 MICRO_VERSION=2
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws22
+EXTRA_VERSION=claws23
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index d3f0863..7123c5b 100644 (file)
@@ -1431,8 +1431,8 @@ static SensitiveCond main_window_get_current_state(MainWindow *mainwin)
                        state |= M_THREADED;
                else
                        state |= M_UNTHREADED;  
-               if (item->folder->type != F_NEWS)
-                       state |= M_ALLOW_DELETE;
+               /*              if (item->folder->type != F_NEWS) */
+               state |= M_ALLOW_DELETE;
 
                if (selection == SUMMARY_NONE && item->hide_read_msgs
                    || selection != SUMMARY_NONE)
index fa7fedb..b655e7f 100644 (file)
@@ -559,7 +559,24 @@ static gint news_get_article_cmd(NNTPSession *session, const gchar *cmd,
 
 static gint news_remove_msg(Folder *folder, FolderItem *item, gint num)
 {
-       return 0;
+       MsgInfo * msginfo;
+       gchar * filename;
+       MsgFlags msgflags = { 0, 0 };
+       gint r;
+
+       filename = folder_item_fetch_msg(item, num);
+       if (filename == NULL)
+               return -1;
+
+       msginfo = procheader_parse(filename, msgflags, FALSE, FALSE);
+       if (msginfo == NULL)
+               return -1;
+
+       r = news_cancel_article(folder, msginfo);
+
+       procmsg_msginfo_free(msginfo);
+
+       return r;
 }
 
 static gint news_get_article(NNTPSession *session, gint num, gchar *filename)
@@ -887,3 +904,44 @@ static void news_delete_all_articles(FolderItem *item)
 
        debug_print(_("done.\n"));
 }
+
+gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
+{
+       gchar * tmp;
+       FILE * tmpfp;
+       gchar buf[BUFFSIZE];
+
+       tmp = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
+                             G_DIR_SEPARATOR, (gint)msginfo);
+       if (tmp == NULL)
+               return -1;
+
+       if ((tmpfp = fopen(tmp, "w")) == NULL) {
+               FILE_OP_ERROR(tmp, "fopen");
+               return -1;
+       }
+       if (change_file_mode_rw(tmpfp, tmp) < 0) {
+               FILE_OP_ERROR(tmp, "chmod");
+               g_warning(_("can't change file mode\n"));
+       }
+       
+       fprintf(tmpfp, "From: %s\r\n", msginfo->from);
+       fprintf(tmpfp, "Newsgroups: %s\r\n", msginfo->newsgroups);
+       fprintf(tmpfp, "Subject: cmsg cancel <%s>\r\n", msginfo->msgid);
+       fprintf(tmpfp, "Control: cancel <%s>\r\n", msginfo->msgid);
+       fprintf(tmpfp, "Approved: %s\r\n", msginfo->from);
+       fprintf(tmpfp, "X-Cancelled-by: %s\r\n", msginfo->from);
+       get_rfc822_date(buf, sizeof(buf));
+       fprintf(tmpfp, "Date: %s\r\n", buf);
+       fprintf(tmpfp, "\r\n");
+       fprintf(tmpfp, "removed with sylpheed\r\n");
+
+       fclose(tmpfp);
+
+       news_post(folder, tmp);
+       remove(tmp);
+
+       g_free(tmp);
+
+       return 0;
+}
index 6280eaa..de3ed77 100644 (file)
@@ -80,4 +80,6 @@ void news_remove_group_list_cache     (Folder         *folder);
 gint news_post                         (Folder         *folder,
                                         const gchar    *file);
 
+gint news_cancel_article(Folder * folder, MsgInfo * msginfo);
+
 #endif /* __NEWS_H__ */
index d4d56c1..99cd015 100644 (file)
@@ -1041,8 +1041,8 @@ static void summary_set_menu_sensitive(SummaryView *summaryview)
 
        if (summaryview->folder_item->folder->type != F_NEWS) {
                menu_set_sensitive(ifactory, "/Move...", TRUE);
-               menu_set_sensitive(ifactory, "/Delete", TRUE);
        }
+       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);
@@ -2859,6 +2859,51 @@ void summary_mark_as_unread(SummaryView *summaryview)
        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);
+               }
+               
+               return found;
+
+       default:
+               return TRUE;
+       }
+}
+
 static void summary_delete_row(SummaryView *summaryview, GtkCTreeNode *row)
 {
        gboolean changed = FALSE;
@@ -2867,6 +2912,9 @@ static void summary_delete_row(SummaryView *summaryview, GtkCTreeNode *row)
 
        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;
@@ -2909,7 +2957,10 @@ void summary_delete(SummaryView *summaryview)
        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;
 
@@ -3481,6 +3532,7 @@ static void summary_execute_delete(SummaryView *summaryview)
        GSList *cur;
 
        trash = summaryview->folder_item->folder->trash;
+
        if (summaryview->folder_item->folder->type == F_MH) {
                g_return_if_fail(trash != NULL);
        }
@@ -3491,10 +3543,11 @@ static void summary_execute_delete(SummaryView *summaryview)
 
        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);
@@ -3502,7 +3555,7 @@ static void summary_execute_delete(SummaryView *summaryview)
        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);
        }