Fix CID 1491370: unchecked return value.
[claws.git] / src / plugins / python / examples / main / Recusively-mark-messages-as-read
blob13b5c2b8658ef9b13ec183e8c7dc5cbaf1e74260
1 # -*- coding: utf-8 -*-
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")
11         # Select given folder
12         clawsmail.folderview_select_folder(folder)
14         # Search for messages with age greater than 28 days
15         clawsmail.quicksearch_search("ag 28", clawsmail.QUICK_SEARCH_EXTENDED)
17         # Mark all messages in the search result as read
18         select_all_action.activate()
19         mark_read_action.activate()
22 # Get selected folder
23 root = clawsmail.get_folderview_selected_folder()
24 if root is None:
25     root = clawsmail.get_folderview_selected_mailbox()
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)
32     # Call above function for all folders.
33     tree.traverse(deal_with_folder)
35     # Clear the quicksearch widget again
36     clawsmail.quicksearch_clear()
38     # Change back to original folder
39     clawsmail.folderview_select(root)