Jean Louis
Jean Louis

Reputation: 455

How to define a custom scheme handler to view Maildir files with mutt

I would like to define a custom scheme handler, something like: muttview:// in order to open terminal and see Maildir in mutt. Mutt shall run something like: mutt -f /home/user/Maildir/[email protected] where this directory would be Maildir.

The URI would like something like this: muttview:///home/user/Maildir/[email protected]

I have tried setting it up like this:

with muttview.desktop in /usr/share/applicatons

[Desktop Entry]
Categories=Office;Network;Email;
Comment=Simple text-based Mail User Agent
Comment[de]=Einfaches, Text-basiertes Mailprogramm
Exec=mutt -f %u
Icon=mutt
Name=mutt
Name[de]=Mutt
MimeType=x-scheme-handler/muttview;
NoDisplay=true
Terminal=true
Type=Application

And in Chrome, it just opens a new browser empty. In Firefox, it opens small terminal which disappears fast.

Where am I wrong?

Upvotes: 1

Views: 232

Answers (1)

Jean Louis
Jean Louis

Reputation: 455

I have found a solution, and would like to answer myself on this one.

First I have created one script to launch my invented muttview: URI scheme.

#!/usr/bin/perl 
use strict;
use warnings;
use feature ':5.10';
use utf8;

binmode(STDOUT, ":encoding(UTF-8)");
binmode(STDIN, ":encoding(UTF-8)");
$| = 1;

exit unless($ARGV[0] =~ /^muttview:/i);
my $uri = $ARGV[0];
my @email = split(':', $uri);
my $email = $email[1];

my $maildir = '/home/data1/protected/Maildir/' . $email;
unless(-d $maildir) {
    system("zenity --info --text 'Maildir: $maildir does not exit'");
} else {
    system("uxterm -e mutt -f '$maildir'");
}

Then I have created in /usr/share/applications a file named: muttview.desktop:

[Desktop Entry]
Categories=Office;Network;Email;
Comment=Simple text-based Mail User Agent
Comment[de]=Einfaches, Text-basiertes Mailprogramm
Exec=/home/data1/protected/bin/MuttView.pl %u
Icon=mutt
Name=mutt
Name[de]=Mutt
MimeType=x-scheme-handler/muttview;
NoDisplay=true
Terminal=true
Type=Application

Then I have run this command:

xdg-settings set default-url-scheme-handler muttview muttview.desktop

And now when I make a link in HTML, like:

<a href="muttview:[email protected]">[email protected]</a>

I get the full list of the Maildir emails of that corresponding user.

My environment is simply IceWm, and I don't use Gnome or KDE.

Upvotes: 1

Related Questions