[Users] how to reply and run an action
berndth at gmx.de
Mon Dec 10 22:14:13 CET 2012
On Mo, 10.12.2012 08:59, Flavio Leitner wrote:
>Looks like the python plugin is the way to go. Is there any
>example out there that you recommend for me to take a look?
Basically, you would choose Tools -> Python scripts -> Browse. This
should open a file browser, where you would navigate to the "main"
subdirectory. There, you would create a file - let's call it
"reply-modify". The contents would look somewhat like this:
import subprocess as sp
# Invoke "Reply" menu item
# The last opened ComposeWindow object is accessible as "clawsmail.compose_window"
# Now, one would typically use PyGTK to modify the message body, which is
# accessible as GtkTextView in "clawsmail.compose_window.text".
# Menu items could also be called on the compose window via
# "clawsmail.compose_window.ui_manager" - but as I said, for some strange reason
# Claws Mail doesn't seem to put Compose Window Actions there.
# So, get the body text as a string, use Python commands to operate on it, or
# call external commands via Python, and write it back.
body_buffer = clawsmail.compose_window.text.get_buffer()
old_body = body_buffer.props.text
proc = sp.Popen(["tr", "[a-z]", "[A-Z]"], stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.STDOUT)
new_body = proc.communicate(old_body)
body_buffer.props.text = new_body
(This example calls "tr [a-z] [A-Z]" on the body to convert it to upper
Then you would choose Tools -> Python scripts -> Refresh (or restart
You could then assign a keyboard shortcut to the script like it's done
for other menu items in Claws Mail, or you could add the script to your
toolbar via Configuration -> Preferences -> Toolbars -> Main Window
(Item type "Plugins").
>I know python, but I don't know the plugin interface.
The startup script in the examples directory adds a "Python API
Documentation" entry in Claws Mail's help menu, which introspects the clawsmail
module and generates HTML on-the-fly. That might be easier to browse than the
console view that Mones told you about.
More information about the Users