[Users] Python - RSSyl folders

Holger Berndt berndth at gmx.de
Mon Aug 5 21:48:11 CEST 2013


On Mo, 05.08.2013 17:45, David Woodfall wrote:

>root = clawsmail.Folder('UK')
>
>Traceback (most recent call last):
>  File
>  "/home/david/.claws-mail/python-scripts/main/mark-all-rss-read.py",
>  line 24, in <module>
>      root = clawsmail.Folder('UK')
>      ValueError: A folder with that path does not exist, and the
>      create parameter was False.
>
>So I put a print(root) statement in there to see exactly what the
>output was when highlighting the UK folder and it outputs what you'd
>expect:
>
>Folder: UK
>
>Can anyone explain why this is happening? 

The Folder constructor needs an identifier, not just a display name
that print shows. See the docs:
=====================================================================
The __init__ function takes two optional arguments:
folder = Folder(identifier, [create_if_not_existing=False])
The identifier is an id string (e.g.
'#mh/Mail/foo/bar'),create_if_not_existing is a boolean expression.
=====================================================================

If you want to print the identifier, use
print(root.get_identifier())

>Ideally, I'd like to run it on "My Feeds" anyway. Is there a reason
>why highlighting this doesn't work.

Yes: It's technically not a folder, but a mailbox. So, when you select
a mailbox, and call get_folderview_selected_folder(), you (rightfully)
won't get anything, because no folder is selected. Which is somewhat
ugly, because there is no accessor for a currently selected mailbox
(there isn't even a mailbox object definition).

For your usecase, one of two workarounds might be usable:

1. Make a specialized script to deal with a hardcoded mailbox, using
the mailbox name (the thing that Claws Mail displays in the folder
view):

Instead of
    clawsmail.get_folder_tree(root)
use
    clawsmail.get_folder_tree("My Feeds")
(or whatever the name is).

This should deal with the entire mailbox, no matter what's currently
selected.

2. Make a script that gets the mailbox name from the currently selected
folder, and marks all items in all folders of that mailbox as read:

Instead of
    clawsmail.get_folder_tree(root)
use
    tree = clawsmail.get_folder_tree(root.mailbox_name)[0]

This is nasty as well, though: It is somewhat ugly as you need to select
a folder in the mailbox, but not the mailbox itself, and it's somewhat
dangerous as it deals with the whole mailbox and thus walks the
hierarchy up and down from the selection. And also, the interface sucks
(get_folder_tree() returns a node when given a folder, but a list when
given a mailbox name).

I guess a better fix would be to introduce a mailbox object, and an
get_folderview_selected_mailbox() accessor in the plugin.

Holger



More information about the Users mailing list