On Sat, Jul 27, 2013 at 08:06:27AM +0900, John Niendorf wrote:

> Today as I was saving about 20 photos I received from my sister, I thought I 
> wonder if there is a way to save all of the images attached to an email in 
> one swoop as opposed to hitting s for each one.
> How do you guys manage attachments?

I wrote this small script; invoke it by "|muttrip dir".  It depends on having 
ripmime installed.  The followup .pl program merely builds a crude index.html 
file and reports how many files it found; you can skip it.

The ripmime args are somewhat of a mystery to me, so I aperiodically change 
them :-)

==== muttrip
    #!/bin/sh

    mkdir -p ~/muttrip/$1 && ripmime -v -i - -d ~/muttrip/$1 --no-nameless 
--infix && $0.pl ~/muttrip/$1

==== muttrip.pl
    #!/usr/bin/perl

    use warnings;
    use strict;

    # Args are dirs to process.

    # Each dir is scanned for files and a rudimentary html file created with 
inline images and links for
    # other files.

    process_dir($_) foreach @ARGV;

    exit 0;

    sub process_dir {
        my $dir = shift;
        opendir(my $dh, $dir) or die "$dir: $!";
        my @files = grep { $_ !~ /^\.\.?$/ } readdir($dh);
        closedir($dh) or die "$dir: $!";
        my @images = ();
        my @others = ();
        foreach my $file (sort @files) {
            if (-d "$dir/$file") {
                process_dir("$dir/$file");
                next;
            }
            if ($file =~ /\.(gif|jpeg|jpg|png|tiff)$/i) {
                push(@images, $file);
            } else {
                push(@others, $file);
            }
        }
        next unless @images || @others;
        my $index = 'index';
        $index .= 'x' while grep { $_ eq "$index.html" } @others;
        open(my $fh, '>', "$dir/$index.html") or die "$dir/$index.html: $!";
        my $title = "$dir: " . @images . '/' . @others;
        print $fh "<html><head><title>$title</head></title>\n<body>\n";
        print $fh "<img src=\"$_\" alt=\"$_\" vspace=\"5\"><br>\n" foreach 
@images;
        print $fh "<a href=\"$_\">$_</a><br>\n" foreach @others;
        print $fh "</body>\n</html>\n";
        close $fh or die "$dir/$index.html: $!";
        print "$title\n";
    }

-- 
            ... _._. ._ ._. . _._. ._. ___ .__ ._. . .__. ._ .. ._.
     Felix Finch: scarecrow repairman & rocket surgeon / fe...@crowfix.com
  GPG = E987 4493 C860 246C 3B1E  6477 7838 76E9 182E 8151 ITAR license #4933
I've found a solution to Fermat's Last Theorem but I see I've run out of room o

Reply via email to