Doug wrote regarding 'Re: [SLE] KMail question' on Tue, Aug 10 at 14:38:
On Tuesday 10 August 2004 12:20, Danny Sauer wrote:
Doug wrote regarding '[SLE] KMail question' on Mon, Aug 09 at 15:13:
I like KMail, and have had no problems with it. (I'm not doing /snip/ It would be even cooler if I could specify the filename extension of the incoming attachment and only copy that file to a specified folder. i.e., if the incoming message was a .doc file, it would automatically copy it to the /home/doug/Documents folder.
Does anybody know of a way to do that? TIA!
Ok, let's see if we can actually solve your probem, then, now that we have a good list of tools to do so. :)
First question which determines how to solve the problem:
How do you get your mail? Is it from a local maildir/mbox file, or do you use pop/imap? Also, do you only receive mail your mail on one machine in one place, or do you require access from multiple machines?
--Danny Under Kmail>settings>configure>Network>Receiving: Name Type Folder dmcgarrett pop inbox
Under Kmail>settings>configure>Network>Sending: name Type Domain dmcgarrett@optonline.net smtp optonline.net
Somewhere else in the configure file, it has "default: maildir" or something to that effect.
[...] Alright. You're popping your mail. The solution I was going to suggest involved setting up fetchmail to pop your message, delivering them locally though procmail, which could then yank the attachments out and put them into another place. However, I then read the kmail docs. :) They allow the use of a filter action called "pipe through" wherin the whole message is sent through a program, and whatever the program prints out replaces the message - if anything's printed. That'll do. So, now all you need is a program that can pull attachments off of messages, save them, and return the message sans attachments. Sounds like a job for perl, since I didn't find anything pre-written. :) ...time passes... I hope this doesn't violate some unspoken list rule, but I wrote something to do what you want. I know you don't do Perl, but if you can manage to install a couple of CPAN modules and can figure out how to change a couple of vars, this oughtta do what you want if you save it to a text file, make it executable, and call it from the pipe filter. You'll have to install Email::MIME and Email::MIME::Attachment::Stripper from CPAN. Ask seperatly if you don't know how to do that. Perl's definatey worth learning, though. It does lots of cool stuff pretty easily. ...start_copy_n_paste... #!/usr/bin/perl -w use Email::MIME; use Email::MIME::Attachment::Stripper; # set your mapping of content-types to destinations here. # mime_type => path/to/folder my %destinations = ( 'image/jpeg' => '/tmp/attachments/jpegs', 'image/gif' => '/tmp/attachments/gifs', 'application/pdf' => '/tmp/attachments/pdfs', ); my $default_destination = '/tmp/attachments'; # read/parse the message my $mail = join('', <>); my $mail_parsed = Email::MIME->new($mail); # pull off attachments and save them appropriately my $stripper = Email::MIME::Attachment::Stripper->new($mail_parsed); my Email::MIME $mail_stripped = $stripper->message; my @attachments = $stripper->attachments; foreach $attachment (@attachments){ my $destination = $default_destination; if(defined($destination = $destinations{$attachment->{'content_type'}})){ $destination = $destinations{$attachment->{'content_type'}} } # compensate for missing filenames (should rarely happen) unless($attachment->{'filename'}){ $attachment->{'filename'} = 'attachment_'.localtime(); } my $outfile = $destination.'/'.$attachment->{'filename'}; open(HANDLE, '>', $outfile) or die "problem with '$outfile': $!"; print HANDLE $attachment->{'payload'}; close HANDLE; } # spit stripped email back out to kmail print $mail_stripped->as_string(); ...end_copy_n_paste... Hopefully that'll work for you. It worked in my limited testing, but if it breaks your mailbox, you get to keep the pieces. The program should be more robust, but this'll work for the common cases. Make sure that the directories exist before running - you could lose mail if you specify a destination folder that doesn't exist (that one of those "robust" things that oughtta be addressed). --Danny, releasing this with no license ;)