Python plugin: Example: Make recursive-mark-as-read also work on mailbox
[claws.git] / src / plugins / python / examples / main / Recusively-mark-messages-as-read
1 # -*- coding: utf-8 -*-
2
3 # Define the function to deal with each folder
4 def deal_with_folder(folder):
5     if folder.num_unread_messages > 0:
6         # Get actions for selecting all messages, and marking the selection as read
7         action_group = clawsmail.get_mainwindow_action_group();
8         select_all_action = action_group.get_action("Edit/SelectAll")
9         mark_read_action = action_group.get_action("Message/Mark/MarkRead")
10         
11         # Select given folder
12         clawsmail.folderview_select_folder(folder)
13         
14         # Search for messages with age greater than 28 days
15         clawsmail.quicksearch_search("ag 28", clawsmail.QUICK_SEARCH_EXTENDED)
16         
17         # Mark all messages in the search result as read
18         select_all_action.activate()
19         mark_read_action.activate()
20
21
22 # Get selected folder
23 root = clawsmail.get_folderview_selected_folder()
24 if root is None:
25     root = clawsmail.get_folderview_selected_mailbox()
26
27 if root is not None:
28     # Get a tree of subfolders. The argument could also be a string of a mailbox name,
29     # or left out for a list of mailbox trees.
30     tree = clawsmail.get_folder_tree(root)
31     
32     # Call above function for all folders.
33     tree.traverse(deal_with_folder)
34     
35     # Clear the quicksearch widget again
36     clawsmail.quicksearch_clear()
37     
38     # Change back to original folder
39     clawsmail.folderview_select(root)