Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

KMail and attachments

2 views
Skip to first unread message

Ami Setton

unread,
Apr 11, 2002, 9:40:33 AM4/11/02
to
Hey all -

KMail seems to keep attachments in the email itself by default - I am
used to Eudora, which decodes them into a directory for me, automatically.

Can KMail do this? What are my options? (BESIDES get used to it :)

TIA

-Ami

Alex Brown

unread,
Apr 11, 2002, 10:05:25 AM4/11/02
to
Ami Setton wrote:

Well, you could do everybody a favour and write a new filter match
message "has attachment"
and action
save attachment into folder <folder>

but apart from that, I can't see how you would do it.

--
Change my email address from exe to com

Ami Setton

unread,
Apr 11, 2002, 10:08:38 AM4/11/02
to

Bummer. Sounds like something worth doing (uh, in theory - I'm not
signing up just yet.) Thanks, though.

blah

unread,
May 15, 2002, 8:18:04 AM5/15/02
to
On Fri, 12 Apr 2002 00:05:25 +1000, Alex Brown wrote:
>
> Well, you could do everybody a favour and write a new filter match
> message "has attachment"
> and action
> save attachment into folder <folder>
>
> but apart from that, I can't see how you would do it.
>

I wrote a perl filter to do exactly this (but read the caveats below). It
requires the Mime Tools Perl module
(http://www.zeegee.com/code/perl/MIME-tools/) to be installed (and
Perl too). The script is pasted in below. Save it as kmdumpb64.pl (eg) and chmod +x.
In KMail, create a new filter and name it (eg 'dump attachments'). I think
i had the filter criteria set to match sender as "*" (wildcard). Filter
action should be set to 'pipe through' kmdumpb64.pl (ie. insert path to
kmdumpb64.pl). You can set it to apply to incoming messages (if you
don't, you can simply use the 'Apply filters' command to selected
messages of your choice.

The filter dumps b64 encoded attachments into the folder of your choice
(this can be set in the script). The filter replaces the attachment with
either a text or html pointer to the dumped file. An html pointer
allows the attachment to be opened when clicked from within Kmail.

I also prefer Eudora's practice of removing encoded attachments. It
allows easy backup of mailboxes of reasonable size. I would like it if
Kmail had this functionality built in. It seems sensible to be able to
store attachments separately.

***CAVEATS***
It's probably buggy - I haven't tested it very much and haven't used it
for quite a while either. It was my intention to test it much more but as
i haven't fully migrated to kmail yet i haven't bothered. It was also my
intention to include the script in a standalone script that could operate
on any mbox format file - i haven't got around to that either.

It's also at http://www4.tpg.com.au/users/cplkjs/kmdumpb64.pl.gz in case the
lines get stuffed up in this post.

Cheers

remove the 'n0sp4m.' to reply.

#!/usr/bin/perl -w

#Copyright C Luton, all rights reserved.
#Released under the same terms as Perl.

use strict;
use MIME::Parser;

# USAGE: "./kmdumpb64.pl < inputfile >outputfile

# create parser
my $parser = new MIME::Parser;
$parser->output_to_core(1);

# Create and set the output directory:
my $dir = "$ENV{'HOME'}/mail-attachments"; #change to suit
(-d "$dir") or mkdir "$dir",0755 or die "mkdir: $!";
(-w "$dir") or die "can't write to directory";
$parser->output_dir("$dir");

# parse the message
my $ent = $parser->parse(\*STDIN);
$ent or die "MIME parsing failed!\n";

# dump b64 attachments and
# replace with pointer to exported file
dump_entity($ent);

# return the stripped message
$ent->print(\*STDOUT);

sub dump_entity {
my $entity = shift;
my @parts = $entity->parts;
my $head = $entity->head;
my $body = $entity->bodyhandle;
my $encoding = $head->mime_encoding;
my $filename_out = $parser->output_path($head);
my $type = $entity->mime_type;

if (@parts) { # multipart...
map { dump_entity($_) } @parts;
}
elsif ($filename_out && $encoding=~m/base64/i) { # singlepart && b64 file
# Dump the b64 encoded file
my $file_io = new IO::File;
$file_io->open("> $filename_out") || die "open file: $!";
$entity->bodyhandle->print( $file_io );
$file_io->close( ) || die "close file: $!";

# Modify the MIME headers
$head->replace('Content-type','text/html');
$head->replace('Content-Disposition','inline');
$head->delete('Content-Transfer-Encoding');

# Write new body
my $bodyIO = new IO::File();
$bodyIO = $body->open("w") || die "open body: $!";

# comment the following line and uncomment the subsequent one for non-html conversion message
$bodyIO->print("Attachment converted: <a href=\"file:/$filename_out\">$filename_out</a>\n");
#$bodyIO->print("Attachment converted: $filename_out\n");

# uncomment this section to display images in message
#if ($type=~m/image/i) {
# $bodyIO->print("<br><img src=\"file:/$filename_out\">\n");
#}

$bodyIO->close || die "close I/O handle: $!";
}
}

Ami Setton

unread,
May 15, 2002, 9:12:38 PM5/15/02
to

Holy, S**t, that's great! I haven't looked at the parser, and I don't
know Perl - but

Two things I think need to be added -

1) Not overwriting files - Eudora would append something to keep
filenames unique. Am I missing something, or does this not do that?

2) Another tool to change the attachments directory, should you decide
to move it. It'd be nice if KMail had a search path for attachments,
but short of that, a search'n'replace tool would be nice. Oh god,
someone's going to tell me it's a one-line sed scripts, aren't they.

That said, it should be ME that gets off my ass and does them. I had to
futz with that "lookout" script to get my outlook 2000 contacts into
kaddressbook - so, deep breath, I'll try to do this - as soon as I get
around to it. (read: when KMail really starts to bother me.)

-Ami

blah

unread,
May 15, 2002, 9:35:52 PM5/15/02
to
>
> Two things I think need to be added -
>
> 1) Not overwriting files - Eudora would append something to keep
> filenames unique. Am I missing something, or does this not do that?

It doesn't overwrite files (this is taken care of by the Mime Tools
module). IIRC, it renames duplicates in a similar fashion to Eudora.

>
> 2) Another tool to change the attachments directory, should you decide
> to move it. It'd be nice if KMail had a search path for attachments,
> but short of that, a search'n'replace tool would be nice. Oh god,
> someone's going to tell me it's a one-line sed scripts, aren't they.
>

You can specify the output directory within the script. So, you could have
several copies of the script each with a different output directory and
assign separate KMail filters to each. Eg. 'ouput to home dir' filter;
'output to ~/mail_attachments'; 'output to ~/Mail/attachments'; etc. Not
very elegant. Like i say, i'd prefer to see this behaviour built in -
this discussion prompted me to submit a feature request.

Ami Setton

unread,
May 15, 2002, 9:53:59 PM5/15/02
to
blah wrote:

>>
>> Two things I think need to be added -
>>
>> 1) Not overwriting files - Eudora would append something to keep
>> filenames unique. Am I missing something, or does this not do that?
>
> It doesn't overwrite files (this is taken care of by the Mime Tools
> module). IIRC, it renames duplicates in a similar fashion to Eudora.
>

Great!! Thanks

>>
>> 2) Another tool to change the attachments directory, should you decide
>> to move it. It'd be nice if KMail had a search path for attachments,
>> but short of that, a search'n'replace tool would be nice. Oh god,
>> someone's going to tell me it's a one-line sed scripts, aren't they.
>>
>
> You can specify the output directory within the script. So, you could
> have several copies of the script each with a different output directory
> and
> assign separate KMail filters to each. Eg. 'ouput to home dir' filter;
> 'output to ~/mail_attachments'; 'output to ~/Mail/attachments'; etc. Not
> very elegant. Like i say, i'd prefer to see this behaviour built in -
> this discussion prompted me to submit a feature request.

I was thinking more about previously filtered attachments in old email-
something after the fact, after it had written the name of the [then]
current attachment directory into the "Attachment Converted" line. So you
move your attachments to the new directory, then run this to re-point all
the links to the right place.

blah

unread,
May 16, 2002, 12:36:49 AM5/16/02
to
On Thu, 16 May 2002 11:53:59 +1000, Ami Setton wrote:
>
>
>>> 2) Another tool to change the attachments directory, should you decide
>>> to move it. It'd be nice if KMail had a search path for attachments,
>>> but short of that, a search'n'replace tool would be nice. Oh god,
>>> someone's going to tell me it's a one-line sed scripts, aren't they.
>>>
>>>
>> You can specify the output directory within the script. So, you could
>> have several copies of the script each with a different output
>> directory and
>> assign separate KMail filters to each. Eg. 'ouput to home dir' filter;
>> 'output to ~/mail_attachments'; 'output to ~/Mail/attachments'; etc.
>> Not very elegant. Like i say, i'd prefer to see this behaviour built
>> in - this discussion prompted me to submit a feature request.
>
> I was thinking more about previously filtered attachments in old email-
> something after the fact, after it had written the name of the [then]
> current attachment directory into the "Attachment Converted" line. So
> you move your attachments to the new directory, then run this to
> re-point all the links to the right place.

i see. like changing "c:\blah\eudora\attachments\" to
"/home/you/attachments"?

i suppose a sed one-liner might work:
sed 's/c:\\blah\\eudora\\attachments\\/\/home\/you\/attachments\//g'
mail.mbx > mail.mbx.new

0 new messages