LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-26-2018, 02:02 AM   #1
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

Rep: Reputation: 47
Cool procmail, attachment, filename


greets,

I'd like to sort mail with procmail based on attachment filename (can be utf8).
what would be simplest way of doing it?

thanks.
 
Old 03-26-2018, 08:53 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,332
Blog Entries: 28

Rep: Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144
It's been a while since I used procmail, but I don't think that's an option. I just tried this

Code:
man procmail | grep attach
and it returned nothing.

This looks like it might be the best reference you can find other than the man page: https://www.howtoforge.com/procmail_tips_recipes
 
Old 03-27-2018, 02:09 AM   #3
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

Original Poster
Rep: Reputation: 47
thanks frankbell.
is there any other command that could extract attachment filename?

I use 'formail' command to sort based on some header fields in procmail:
Code:
:0 h
SUBJECT=| formail -cXSubject

:0 h
RECEIVED=| formail -cXReceived

...

* RECEIVED ?? .*(gmail.com).*
edit:
I've tried this:
Code:
ripmime -v -i message.txt
but can't make it save files to /dev/null and keep just the 'verbosity'

Last edited by qrange; 03-27-2018 at 02:19 AM.
 
Old 03-28-2018, 07:32 PM   #4
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,732

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
An attachment would be a MIME multipart entry which procmail should see in the body of the message
Example:
Code:
------=_Part_97538_31053862.1521746603365
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; 
	name="somespreadsheetname.xlsx"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; 
	filename="somespreadsheetname.xlsx"
...so try a body recipe for Content-Type followed by name or filename on a subsequent line.
Don't have that off the top of my head, but
Code:
man procmailrc
might help...or the link frankbell provided

Use your email client's "view source" command or view the file in the Maildir directly with less or more to see what's procmail is working with.
If using the mbox format, you should be able to less the file, but will have to then search for an individual email with an attachment.
 
1 members found this post helpful.
Old 03-30-2018, 08:18 AM   #5
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

Original Poster
Rep: Reputation: 47
thanks scasey.
I'm using fetchmail, think its mbox format.
I've come up with this:
Code:
grep  -A3 'Content-Type:' email.txt  |grep -A2 name= |tr -d '\n' |sed -n 's/.*name="\(.*\)"Content-.*/\1/p'; echo
seems that filenames can get split across few lines.
if someone can verify, please do.
thanks.

edit: unfortunately this seem to return only first filename

Last edited by qrange; 03-30-2018 at 08:23 AM.
 
Old 03-30-2018, 09:25 AM   #6
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,732

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
What about something like (untested)
Code:
:0 B
filename=somefilename.xls
{
   ##route to whereever
}
...assumes you know the attachment name, of course.
 
1 members found this post helpful.
Old 03-30-2018, 12:50 PM   #7
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

Original Poster
Rep: Reputation: 47
trouble is, the text might contain 'name=' (one never can be sure...).
I don't know the exact attachment name, I'd need to use wildcards for 'routing' mail.

I need 'sed' to do multiple replace.

this sortof works:
Code:
grep  -A3 'Content-Type: application' email.txt  |grep -A2 name= |grep -o '".*"' |sed 's/"//g'
dunno what happens if filename contains "

Last edited by qrange; 03-30-2018 at 01:48 PM.
 
Old 04-01-2018, 05:59 PM   #8
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,732

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by qrange View Post
dunno what happens if filename contains "
Send yourself an email with an attachment containing a " and see what happens
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
procmail catch email with attachment packets Linux - Software 1 09-23-2013 11:55 AM
procmail procmailrc attachment filtering ted_chou12 Linux - Software 7 04-12-2011 11:56 AM
save mail attachment with procmail graveworm Linux - Networking 2 01-08-2007 08:31 AM
Removing Attachment With Procmail joseph Linux - Networking 0 02-17-2005 07:32 PM
Procmail Store Mail Attachment mark@mark-goebl Linux - Software 1 01-09-2003 10:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration