LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux > 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

Tags used in this thread
Popular LQ Tags , , , ,

Reply
 
Thread Tools
Old 07-13-2008, 05:37 PM   #1
Bogus8
Member
 
Registered: Oct 2003
Distribution: Slackware (Soon)
Posts: 34
Thanked: 0
Question how to truncate email (with procmail?)


[Log in to get rid of this advertisement]
I'm looking to use fetchmail to recieve my email from my ISP and then truncate most of them down to like 150 characters and then forward it back out.

I'm assuming procmail is the best middle step there for that truncating but I can't seem to figure out the best way to do it.
Bogus8 is offline  
Tag This Post , , , ,
Reply With Quote
Old 07-14-2008, 01:10 AM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,511
Thanked: 4
This is going to be a little tricky.

The body of email includes the Headers and the Body Text. Do you want headers included (without those, you don't see things like From:, Subject:, Date:, etc.

The body of email is often mime encoded, and just truncating will likely not give you the results you want. Only for plain text (non-mime encoded) mail will the results be generally useful.

Can you describe what you end goal is ?
Mr. C. is offline     Reply With Quote
Old 07-14-2008, 03:00 AM   #3
Bogus8
Member
 
Registered: Oct 2003
Distribution: Slackware (Soon)
Posts: 34
Thanked: 0

Original Poster
Guess, that would make more sense...

I'm making a poor man's blackberry... I get unlimited incoming text messages on my phone. I'm limited at 160 characters per message and I really don't want to get multi-part messages for long emails. I just mainly want to snag the subject and what else will fit from the body till the 160 limit. It all goes back out via ISP's SMTP server (my cell company gives me an email address to send me text msg's).

Hopefully that will help figure out what I'm doing
Bogus8 is offline     Reply With Quote
Old 07-14-2008, 03:21 AM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,511
Thanked: 4
That's what I was thinking you were doing.

There are numerous MIME tools available for perl (and other languages too). You could create a stripper app, and use procmail to call it.
Mr. C. is offline     Reply With Quote
Old 07-14-2008, 11:46 AM   #5
Bogus8
Member
 
Registered: Oct 2003
Distribution: Slackware (Soon)
Posts: 34
Thanked: 0

Original Poster
Yeah, I figured I'd need to call an app... hoping I wouldn't need to write one in perl or something... I can do some bash scripting but I haven't don't much perl yet. My past experience says Perl and I don't get along
Bogus8 is offline     Reply With Quote
Old 07-14-2008, 12:26 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 16,716
Blog Entries: 30
Thanked: 283
Thinking about whipping up a procmail recipe: given a single e-mail message, then piping it through 'formail -k -X Subject:' will strip off all headers except the subject, then piping it through 'xargs' will give you one space separated string, then piping it through cut will cut it off at $charcount (rather than using string=${string:0:169}, then stripping string=${string//Subject: /} will give you the whole onehundredandsixty chars to e-mail back out. Could be a very small shell script.
unSpawn is offline     Reply With Quote
Old 07-14-2008, 01:33 PM   #7
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,511
Thanked: 4
Quote:
Originally Posted by unSpawn View Post
Thinking about whipping up a procmail recipe: given a single e-mail message, then piping it through 'formail -k -X Subject:' will strip off all headers except the subject, then piping it through 'xargs' will give you one space separated string, then piping it through cut will cut it off at $charcount (rather than using string=${string:0:169}, then stripping string=${string//Subject: /} will give you the whole onehundredandsixty chars to e-mail back out. Could be a very small shell script.
Right, but this isn't the issue. The issue is that the first portion of the body of an email can be all MIME headers and sections. For example:

Code:
This is a multi-part message in MIME format.

------=_NextPart_000_0006_01C8E011.A194AB80
Content-Type: text/plain;
charset="iso-8859-2"
Content-Transfer-Encoding: 7bit
This is 170 characters. It is not until *after* those headers is there anything interesting:

Code:
Good evening.

Wanted!
But it may not be that way either. The text/plain portion could be at the end of the mime encapsulation, and one might end up with this:

Code:
UEsDBBQAAgAIAIBR5jhVga4fdJ4AAACkAAAIAAAAZmlsbS5zY3Lst3OUsD3TJ9i2bdu27e67bdu2
bdu2bdvuvtu27d7n/d5vsDs7O7t/zjn7O6euSlKVSiWppHLJasYDAAMAAID8Q7+/AADtAP+GAMD
So the problem is not trivial.
Mr. C. is offline     Reply With Quote
Old 07-14-2008, 09:29 PM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 16,716
Blog Entries: 30
Thanked: 283
Clearly I read over the "that being not the issue" part. Still should be doable either using some procmail recipe from here or here or your "stripper app" as you already suggested.
unSpawn is offline     Reply With Quote
Old 07-14-2008, 09:57 PM   #9
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,511
Thanked: 4
Looks good - I haven't spent much time with procmail, so didn't know what capabilities it had. Good reference, thanks.
Mr. C. is offline     Reply With Quote
Old 07-14-2008, 10:26 PM   #10
Bogus8
Member
 
Registered: Oct 2003
Distribution: Slackware (Soon)
Posts: 34
Thanked: 0

Original Poster
I didn't fall out... just reading reading here.
Bogus8 is offline     Reply With Quote
Old 07-14-2008, 11:35 PM   #11
Bogus8
Member
 
Registered: Oct 2003
Distribution: Slackware (Soon)
Posts: 34
Thanked: 0

Original Poster
Quote:
Originally Posted by unSpawn View Post
Clearly I read over the "that being not the issue" part. Still should be doable either using some procmail recipe from here or here or your "stripper app" as you already suggested.
I read through all that and then come across the last part of that first page which is EXACTLY what I'm doing! Granted I still need to research it more as I don't really get how it all goes together and I want to do some crazy stuff where I can query a database via a text message sent to my email... so I'll need to learn more about how to decode the body and recognize "commands" to do that with.
Bogus8 is offline     Reply With Quote
Old 07-22-2008, 07:51 PM   #12
unSpawn
Moderator
 
Registered: May 2001
Posts: 16,716
Blog Entries: 30
Thanked: 283
Quote:
Originally Posted by Bogus8 View Post
Granted I still need to research it more as I don't really get how it all goes together
Just post your recipes and we'll try to help you along.


Quote:
Originally Posted by Bogus8 View Post
I want to do some crazy stuff where I can query a database via a text message sent to my email
You mean like spam or what?
unSpawn is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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
Email Stops Working w/ Procmail (Postfix) Carlwill Linux - Server 2 03-26-2008 06:28 PM
Anyone Filter Email w/ Procmail Carlwill Linux - Server 10 03-14-2008 04:07 PM
LXer: Process your email with procmail LXer Syndicated Linux News 0 04-14-2006 09:03 AM
How to get procmail to send a copy of an email lmcilwain Linux - Software 0 03-02-2006 02:16 PM
Procmail, Sendmail, quotas and bounced Email mickyman Linux - Security 1 02-14-2006 07:06 AM


All times are GMT -5. The time now is 01:19 PM.

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration