Difference between revisions of "Using Claws Mail with other programs"

From Claws Mail FAQ
Jump to navigationJump to search
m
 
 
(24 intermediate revisions by 4 users not shown)
Line 42: Line 42:
 
=== How can I use Claws Mail with Popfile? ===
 
=== How can I use Claws Mail with Popfile? ===
 
You can reclass messages received trough a Popfile filter with a header link or a button in Claws Mail.
 
You can reclass messages received trough a Popfile filter with a header link or a button in Claws Mail.
Popfile lives @ http://popfile.sourceforge.net/  
+
Popfile lives @ http://getpopfile.org/  
  
 
First read the Popfile documentation on how to set up the mail client to use Popfile.
 
First read the Popfile documentation on how to set up the mail client to use Popfile.
Line 91: Line 91:
 
Menu > Configuration > Actions
 
Menu > Configuration > Actions
 
<br>  In 'Menu Name' add "Mark as Spam"
 
<br>  In 'Menu Name' add "Mark as Spam"
<br>  In 'Command line' add -sa-learn --spam %F-
+
<br>  In 'Command line' add "sa-learn --spam %F"
 
<br>  click the Add button
 
<br>  click the Add button
 
<br>
 
<br>
 
Menu > Configuration > Actions
 
Menu > Configuration > Actions
 
<br>  In 'Menu Name' add "Mark as Ham"
 
<br>  In 'Menu Name' add "Mark as Ham"
<br>  In 'Command line' add -sa-learn --ham %F-
+
<br>  In 'Command line' add "sa-learn --ham %F"
 
<br>  click the Add button
 
<br>  click the Add button
 
<br> then select a message, <b>Menu Tools > Actions</b>
 
<br> then select a message, <b>Menu Tools > Actions</b>
 
will have the new actions to mark your email as Spam/Ham. Once you click one of the buttons spamassassin will process your request - this takes time so be patient and dont click on the 'cancel' button.
 
will have the new actions to mark your email as Spam/Ham. Once you click one of the buttons spamassassin will process your request - this takes time so be patient and dont click on the 'cancel' button.
  
[[Note:]]
+
Note:
 
<br>
 
<br>
 
If you want to have the mail learned on a remote mail server, that's possible with a 'Command line' like this:
 
If you want to have the mail learned on a remote mail server, that's possible with a 'Command line' like this:
Line 118: Line 118:
 
into the "Web Browser" field.
 
into the "Web Browser" field.
  
=== How can I use Claws mail with Firefox ===
+
=== How can I use Claws Mail with Firefox? ===
  
 
Go to Menu > Configuration > Preferences > Message View > External Programs
 
Go to Menu > Configuration > Preferences > Message View > External Programs
Line 127: Line 127:
 
into the "Web Browser" field.
 
into the "Web Browser" field.
 
See [http://kb.mozillazine.org/Command_line_arguments Firefox's Command line arguments] for more information.
 
See [http://kb.mozillazine.org/Command_line_arguments Firefox's Command line arguments] for more information.
 +
 +
See also: [https://www.claws-mail.org/faq/index.php?title=Installation_and_Configuration#How_can_I_tell_my_browser.2Fnewsclient.2Fother_program_to_use_Claws_Mail_as_e-mail_program.3F How can I tell my browser/newsclient/other program to use Claws Mail as e-mail program?]
  
 
=== How can I use Claws Mail with mairix? ===
 
=== How can I use Claws Mail with mairix? ===
Line 135: Line 137:
 
To illustrate this topic, we'll detail the necessary steps to make a global search in a MH config (in our example, ~/Mail).
 
To illustrate this topic, we'll detail the necessary steps to make a global search in a MH config (in our example, ~/Mail).
  
- install mairix from http://www.rpcurnow.force9.co.uk/mairix/ or get it from your packages repository. mairix is a program for indexing and searching email messages stored in Maildir, MH or mbox folders. We recommend to avoid using version 0.20 (0.17 to 0.19 are fine).
+
- install mairix from https://github.com/rc0/mairix or get it from your packages repository. mairix is a program for indexing and searching email messages stored in Maildir, MH or mbox folders. We recommend to avoid using version 0.20 (0.17 to 0.19 are fine).
  
 
- create a folder in Claws Mail where the search results will be stored in (in
 
- create a folder in Claws Mail where the search results will be stored in (in
Line 161: Line 163:
 
</pre>
 
</pre>
  
make sure that you've installed mairix.sh from the Tools pages (http://www.claws-mail.org/tools/claws-mail-mairix.tar.gz) into ~/.claws-mail/tools or wherever you want, provided that you set the correct path in the action text.
+
make sure that you've installed mairix.sh from the Tools pages (https://www.claws-mail.org/tools/claws-mail-mairix.tar.gz) into ~/.claws-mail/tools or wherever you want, provided that you set the correct path in the action text.
  
 
Now call the action. You'll be asked for the text to search for. Search results - symlinks to the existing message files, will be placed into the target folder, making it like a virtual folder. Removing messages from that folder will NOT remove the original message files. The text to search for is an expression to pass to mairix. See `man mairix` for all search
 
Now call the action. You'll be asked for the text to search for. Search results - symlinks to the existing message files, will be placed into the target folder, making it like a virtual folder. Removing messages from that folder will NOT remove the original message files. The text to search for is an expression to pass to mairix. See `man mairix` for all search
Line 168: Line 170:
  
 
You can create as many mairix config files as you want (be sure that you set a different database value in each of them), then create the corresponding actions that call mairix.sh with the config filename in parameter.
 
You can create as many mairix config files as you want (be sure that you set a different database value in each of them), then create the corresponding actions that call mairix.sh with the config filename in parameter.
 +
 +
=== How can I use Claws Mail with httppc? ===
 +
 +
If you need to use Claws Mail behind an HTTP proxy that supports "CONNECT" method (RFC 2616), you may want to use [http://httppc.sourceforge.net/ httppc library]: it's a simple and fast way to achieve this goal.
 +
 +
An step-by-step example of how to set up version 0.8.5 follows.
 +
 +
First we need to get the source archive from the SourceForge repository and unpack it:
 +
<pre>
 +
wget "http://downloads.sourceforge.net/project/httppc/httppc/0.8.5/httppc-0.8.5.tar.gz"
 +
tar xzf httppc-0.8.5.tar.gz
 +
cd httppc-0.8.5
 +
</pre>
 +
 +
Then we run the configure script:
 +
<pre>
 +
sh ./configure
 +
</pre>
 +
'''''Note:''''' By default, the package's files are installed in `/usr/local/bin', `/usr/local/man', etc. If you wish to specify another location for these files, you can specify an installation prefix other than `/usr/local' by giving `configure' the option `--prefix=PATH'. Please refer to the INSTALL file for further information.
 +
 +
Finally we build and install it:
 +
<pre>
 +
make
 +
make check #optional
 +
make install
 +
</pre>
 +
 +
'''''Note:''''' You may encounter an error while compiling driver.c, stating
 +
<pre>
 +
driver.c: In function 'getaddrinfo':
 +
driver.c:557:13: error: 'EAI_NODATA' undeclared
 +
</pre>
 +
In this case, just insert the "-D_GNU_SOURCE" option in the Makefile, for instance in the "DEFS" line:
 +
<pre>
 +
DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H -DCONF_SYS_WIDE=\"$(DESTDIR)$(sysconfdir)/$(PACKAGE)rc\"
 +
</pre>
 +
 +
We now need to edit the configuration a bit to make it fully functional:
 +
* First, the proxed shell script (located at /usr/local/bin/proxed by default). Define at least the $HTTP_PROXY variable.
 +
* Then the httppc configuration file (located at /usr/local/etc/httppcrc by default). Define at least the proxy parameter, and most probably the ldns parameter if you have a local DNS server behind the HTTP proxy as well.
 +
 +
We should be all set. The script should be in our path and can be launched with
 +
<pre>
 +
proxed claws-mail
 +
</pre>
 +
 +
'''''Tip:''''' We can add a shell alias to launch typing less (example for ~/.bashrc):
 +
<pre>
 +
alias claws-mail="proxed claws-mail &"
 +
</pre>
 +
 +
=== Integrating Claws-mail with Taskwarrior ===
 +
 +
==== System Requirements ====
 +
 +
You need Claws-mail and Taskwarrior installed, then [https://github.com/GothenburgBitFactory/tasklib Tasklib] package as well as [https://github.com/jschlatow/taskopen Taskopen].
 +
 +
==== Integration script ====
 +
 +
In order to integrate Claws-mail &amp; Taskwarrior you need the following script somewhere in your <code>PATH</code>.
 +
 +
Name it <code>claws2task</code>.
 +
 +
<pre class="Python">#!/usr/bin/env python3
 +
 +
&quot;&quot;&quot;
 +
Creates a new task with the given message's filename as annotation attachment.
 +
&quot;&quot;&quot;
 +
 +
import email
 +
import sys
 +
 +
from tasklib import TaskWarrior, Task
 +
 +
 +
def get_task_description(message):
 +
    description = 'claws: &quot;{}&quot;'.format(message['subject'])
 +
    return description
 +
 +
 +
def main():
 +
    try:
 +
        file_name = sys.argv[1]
 +
        fp = open(file_name)
 +
        message = email.message_from_file(fp)
 +
        desc = get_task_description(message)
 +
        tw = TaskWarrior(data_location='~/task', create=False)
 +
        tw.overrides['gc'] = '0'
 +
        task = Task(tw, description=desc, tags=['inbox','email'])
 +
        task.save()
 +
        task.add_annotation(str(file_name))
 +
    except Exception as e:
 +
        print(e)
 +
        sys.exit(2)
 +
 +
if __name__ == &quot;__main__&quot;:
 +
    main()
 +
</pre>
 +
 +
==== Tagging Messages ====
 +
 +
<pre class="Python">task = Task(tw, description=desc, tags=['inbox','email'])
 +
task.save()
 +
</pre>
 +
 +
Every task created within Claws-mail gets two tags: <code>+inbox</code> and <code>+email</code> and gets annotated with the link to open it from Taskwarrior. Also, the task's description is the message's <code>Subject</code> prepended with <code>claws:</code>. You can adjust that according to your preferences.
 +
 +
==== Add a User Action in Claws-mail ====
 +
 +
You need to add the following action as a "shell command" in Claws Mail:
 +
 +
 +
<code>/path/to/the/script/claws2task %f</code>
 +
 +
 +
Running this Action on a message will create a new Taskwarrior task.
 +
 +
 +
[See https://claws-mail.org/faq/index.php/Actions on setting up an Action]
 +
 +
==== MIME Setup ====
 +
 +
In order to be able to (task)open the message in Claws-mail, we need to configure it for <code>xdg-open</code>.
 +
 +
If you query a mail/news message with
 +
 +
<code>xdg-mime query filetype ~/Mail/Inbox/12345</code> (for an MH mailbox)
 +
 +
or
 +
 +
<code>xdg-mime query filetype ~/.claws-mail/imapcache/some/mail/account/INBOX/12345</code> (for an IMAP mailbox)
 +
 +
you should get:
 +
 +
<code>message/rfc822 </code>for an email message and <code>message/news</code> for an NNTP message.
 +
 +
===== System Integration =====
 +
 +
Create the following file:
 +
 +
<pre>[Desktop Entry]
 +
Version=1.0
 +
Type=Application
 +
Name=Claws-mail Select Handler
 +
Comment=Claws-mail integration with Taskwarrior
 +
Icon=applications-other
 +
Exec=claws-mail --select %u
 +
MimeType=x-scheme-handler/claws-select;
 +
</pre>
 +
 +
as <code>~/.local/share/applications/claws-select.desktop</code> and then configure 2 new filetypes with:
 +
 +
<pre>
 +
xdg-mime default claws-select.desktop message/rfc822
 +
 +
xdg-mime default claws-select.desktop message/news
 +
</pre>
 +
 +
Check that everything is OK with:
 +
 +
<pre>
 +
$ env XDG_UTILS_DEBUG_LEVEL=10  xdg-mime query default message/rfc822
 +
</pre>
 +
 +
and
 +
 +
<pre>
 +
$ env XDG_UTILS_DEBUG_LEVEL=10  xdg-mime query default message/news
 +
</pre>
 +
 +
==== Testing ====
 +
 +
Now you can test opening a mail/news message with <code>xdg-open</code> in your <code>terminal</code>.
 +
 +
Finally, after you've created task #xyz within Claws Mail, you will be able to see it in Taskwarrior --- filter with
 +
<code>+inbox +email</code> and then you will be able to issue:
 +
 +
<code>$ task open #xyz </code>
 +
 +
and you will see it it higlighted in Claws Mail.

Latest revision as of 13:35, 11 October 2021

How can I use Claws Mail with bogofilter?

The simplest method is to use the Bogofilter plugin, see the Plugins FAQ Page for further information. If you use that plugin, the following will not be needed

Filtering/Actions method

First of all, make sure you have trained bogofilter; for different training methods, see http://bogofilter.sourceforge.net/faq.shtml#training. Method 4 is recommended, but requires a large number of ham and spam messages.

Add a new filtering rule: you need a filtering condition which runs bogofilter on incoming messages; and an action that has to be performed if the message was recognised as spam. Go to the Filtering Configuration dialog, and type the following in the condition entry field:

test "bogofilter -u < %F"

Note 1: this assumes that bogofilter is in your path!
Note 2: the -u parameter of bogofilter registers the message automatically as either spam or ham.

Next add an action in the Action field. The best way is to use the Define... button next to the field. As an example, if you wanted to move a spam messages to a directory called Spam, then the final action, put in the field, could look like this:

move "#mh/Mailbox/Spam"

After having added the filtering rule you probably want to create two Claws Mail Actions: one for marking messages as spam, and one for marking messages as ham. These actions can be used to correct bogofilter and/or to train it with additional messages. For example, if the above filtering rule did not detect a spam message correctly, delivering it to your inbox, you can manually correct this by invoking a "Mark As Spam" action. As an added bonus, Actions are automatically added to the main menu (under Tools|Actions), and can also be added to the main toolbar.

Open the Actions dialog (Configuration | Actions...). In the Menu name field, enter the following:

Mark As Spam

This is just the text as it would appear in the Tools|Actions submenu.

The accompanying command line for Mark As Spam should be:

bogofilter -Ns -B %F

(Don't forget to use the Add button!)

Likewise, the same thing you should do for marking messages as ham. Select "New" in the Current actions list, and enter the following in the Menu name:

Mark As Ham

The command line for this action should be:

bogofilter -Sn -B %F

And add the action by clicking the Add button.

This gives you a basic setup for bogofilter and Claws Mail.

How can I use Claws Mail with Popfile?

You can reclass messages received trough a Popfile filter with a header link or a button in Claws Mail. Popfile lives @ http://getpopfile.org/

First read the Popfile documentation on how to set up the mail client to use Popfile.

You have 2 options to reclass received messages: a simple one (header link) and a difficult one (toolbar button).

1) Simple method

  • Open the Popfile control center, go to the "Buckets" tab, and make sure ALL buckets have the X-POPFile-Link Header turned on.
  • Open Claws Mail preferences window, go to Message view -> Text options.
  • Edit the header display options, in the "Displayed header configuration" dialog add X-POPFile-Link to the displayed headers.
  • All messages received via Popfile will have a header link (just above the message body) called X-POPFile-Link, something like this: X-POPFile-Link: http://127.0.0.1:7070/jump_to_message?view=6491 - you can click on it and Claws will open the link with the browser you set up in preferences.

2) difficult method

You will need 3 things:

  • a bash script
  • a Claws Mail action
  • change Popfile configuration a bit.

The bash script:

#!/bin/bash
url=`cat $1 | grep -e X-POPFile-Link:.* -o|grep http.* -o`
firefox $url

Save it as /some/path/popreclass.sh
Change firefox to another browser executable if needed.

The action:
/some/path/popreclass.sh "%f"
You can set up a toolbar buttor for the action later

Popfile configuration
Go to http://127.0.0.1:8080/configuration, and make sure the X-POPFile-Link Header option is turned ON.
Your popfile URL might be different.

You will be able to reclass messages that were received with the above option turned ON.

How can I use Claws Mail with SpamAssassin?

The simplest method is to use the SpamAssassin plugin, see the Plugins FAQ Page for further information.

Filtering/Actions method

To train spamassassin in Claws Mail (>=1.9.6):
Menu > Configuration > Actions
In 'Menu Name' add "Mark as Spam"
In 'Command line' add "sa-learn --spam %F"
click the Add button
Menu > Configuration > Actions
In 'Menu Name' add "Mark as Ham"
In 'Command line' add "sa-learn --ham %F"
click the Add button
then select a message, Menu Tools > Actions will have the new actions to mark your email as Spam/Ham. Once you click one of the buttons spamassassin will process your request - this takes time so be patient and dont click on the 'cancel' button.

Note:
If you want to have the mail learned on a remote mail server, that's possible with a 'Command line' like this:
ssh host.domain sa-learn --ham < %f
It works best if you have already setup ssh to use keys for authentication.

How can I use Claws Mail with Mozilla? (not Firefox)

Go to Menu > Configuration > Preferences > Message View > External Programs

and write

mozilla -remote "openurl(%s,new-window)"

into the "Web Browser" field.

How can I use Claws Mail with Firefox?

Go to Menu > Configuration > Preferences > Message View > External Programs

and write

firefox --new-tab "%s"

into the "Web Browser" field. See Firefox's Command line arguments for more information.

See also: How can I tell my browser/newsclient/other program to use Claws Mail as e-mail program?

How can I use Claws Mail with mairix?

In addition to the quicksearch, that allows filtering out messages in folders recursively, you can use mairix in Claws Mail in order to perform message searches across a wide range of folders.

To illustrate this topic, we'll detail the necessary steps to make a global search in a MH config (in our example, ~/Mail).

- install mairix from https://github.com/rc0/mairix or get it from your packages repository. mairix is a program for indexing and searching email messages stored in Maildir, MH or mbox folders. We recommend to avoid using version 0.20 (0.17 to 0.19 are fine).

- create a folder in Claws Mail where the search results will be stored in (in our example: ~/Mail/Search).

- create a mairix config file (~/.mairixrc for instance):

base=~/Mail
mh=*...
omit=draft:queue:trash:Junk:Search
database=~/.mairix_db
mfolder=Search
mformat=mh

in that example, the base directory is ~/Mail, the search will be performed across all folders and sub-folders (mh=*...) in the base directory. Search will omit drafts, queue, trash, Junk and Search folders located in the base directory, and will place results into the Search folder. If you're in the search folder prior to starting the search, you'll have to select click "View/Update summary" to refresh the messages list.

See `man mairix` for more information about the mairix configuration file.

- add an action in Claws Mail to start the mairix search:

> ~/.claws-mail/tools/mairix.sh ~/.mairixrc

make sure that you've installed mairix.sh from the Tools pages (https://www.claws-mail.org/tools/claws-mail-mairix.tar.gz) into ~/.claws-mail/tools or wherever you want, provided that you set the correct path in the action text.

Now call the action. You'll be asked for the text to search for. Search results - symlinks to the existing message files, will be placed into the target folder, making it like a virtual folder. Removing messages from that folder will NOT remove the original message files. The text to search for is an expression to pass to mairix. See `man mairix` for all search patterns.


You can create as many mairix config files as you want (be sure that you set a different database value in each of them), then create the corresponding actions that call mairix.sh with the config filename in parameter.

How can I use Claws Mail with httppc?

If you need to use Claws Mail behind an HTTP proxy that supports "CONNECT" method (RFC 2616), you may want to use httppc library: it's a simple and fast way to achieve this goal.

An step-by-step example of how to set up version 0.8.5 follows.

First we need to get the source archive from the SourceForge repository and unpack it:

wget "http://downloads.sourceforge.net/project/httppc/httppc/0.8.5/httppc-0.8.5.tar.gz"
tar xzf httppc-0.8.5.tar.gz
cd httppc-0.8.5

Then we run the configure script:

sh ./configure

Note: By default, the package's files are installed in `/usr/local/bin', `/usr/local/man', etc. If you wish to specify another location for these files, you can specify an installation prefix other than `/usr/local' by giving `configure' the option `--prefix=PATH'. Please refer to the INSTALL file for further information.

Finally we build and install it:

make
make check #optional
make install

Note: You may encounter an error while compiling driver.c, stating

driver.c: In function 'getaddrinfo':
driver.c:557:13: error: 'EAI_NODATA' undeclared

In this case, just insert the "-D_GNU_SOURCE" option in the Makefile, for instance in the "DEFS" line:

DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H -DCONF_SYS_WIDE=\"$(DESTDIR)$(sysconfdir)/$(PACKAGE)rc\"

We now need to edit the configuration a bit to make it fully functional:

  • First, the proxed shell script (located at /usr/local/bin/proxed by default). Define at least the $HTTP_PROXY variable.
  • Then the httppc configuration file (located at /usr/local/etc/httppcrc by default). Define at least the proxy parameter, and most probably the ldns parameter if you have a local DNS server behind the HTTP proxy as well.

We should be all set. The script should be in our path and can be launched with

proxed claws-mail

Tip: We can add a shell alias to launch typing less (example for ~/.bashrc):

alias claws-mail="proxed claws-mail &"

Integrating Claws-mail with Taskwarrior

System Requirements

You need Claws-mail and Taskwarrior installed, then Tasklib package as well as Taskopen.

Integration script

In order to integrate Claws-mail & Taskwarrior you need the following script somewhere in your PATH.

Name it claws2task.

#!/usr/bin/env python3

""" 
Creates a new task with the given message's filename as annotation attachment.
"""

import email
import sys

from tasklib import TaskWarrior, Task


def get_task_description(message):
    description = 'claws: "{}"'.format(message['subject'])
    return description 


def main():
    try:
        file_name = sys.argv[1]
        fp = open(file_name)
        message = email.message_from_file(fp)
        desc = get_task_description(message)
        tw = TaskWarrior(data_location='~/task', create=False)
        tw.overrides['gc'] = '0'
        task = Task(tw, description=desc, tags=['inbox','email'])
        task.save()
        task.add_annotation(str(file_name))
    except Exception as e:
        print(e)
        sys.exit(2)

if __name__ == "__main__":
    main()

Tagging Messages

task = Task(tw, description=desc, tags=['inbox','email'])
task.save()

Every task created within Claws-mail gets two tags: +inbox and +email and gets annotated with the link to open it from Taskwarrior. Also, the task's description is the message's Subject prepended with claws:. You can adjust that according to your preferences.

Add a User Action in Claws-mail

You need to add the following action as a "shell command" in Claws Mail:


/path/to/the/script/claws2task %f


Running this Action on a message will create a new Taskwarrior task.


[See https://claws-mail.org/faq/index.php/Actions on setting up an Action]

MIME Setup

In order to be able to (task)open the message in Claws-mail, we need to configure it for xdg-open.

If you query a mail/news message with

xdg-mime query filetype ~/Mail/Inbox/12345 (for an MH mailbox)

or

xdg-mime query filetype ~/.claws-mail/imapcache/some/mail/account/INBOX/12345 (for an IMAP mailbox)

you should get:

message/rfc822 for an email message and message/news for an NNTP message.

System Integration

Create the following file:

[Desktop Entry]
Version=1.0
Type=Application
Name=Claws-mail Select Handler
Comment=Claws-mail integration with Taskwarrior
Icon=applications-other
Exec=claws-mail --select %u
MimeType=x-scheme-handler/claws-select;

as ~/.local/share/applications/claws-select.desktop and then configure 2 new filetypes with:

xdg-mime default claws-select.desktop message/rfc822

xdg-mime default claws-select.desktop message/news

Check that everything is OK with:

$ env XDG_UTILS_DEBUG_LEVEL=10  xdg-mime query default message/rfc822

and

$ env XDG_UTILS_DEBUG_LEVEL=10  xdg-mime query default message/news

Testing

Now you can test opening a mail/news message with xdg-open in your terminal.

Finally, after you've created task #xyz within Claws Mail, you will be able to see it in Taskwarrior --- filter with +inbox +email and then you will be able to issue:

$ task open #xyz

and you will see it it higlighted in Claws Mail.