LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 02-27-2008, 10:50 AM   #1
Sheridan
Member
 
Registered: Aug 2007
Location: Hungary
Distribution: Fedora, CentOS
Posts: 89

Rep: Reputation: 21
Rewriting mail subject with Formail


Hi Guys,

I've done a little script that redirects all PHP mails to a single mailbox from the development server using formail and sendmail. The script is like this:

Code:
#!/bin/bash
/usr/bin/formail -R to X-original-to -R cc X-original-cc -R bcc X-original-bcc -f -A "to: betadump@mycompany.com" | sendmail -t -i
Essentially, you call this script exactly like you would call sendmail. For example:

Code:
> echo "test mail" | ./mrewrite my@address.com
It works as far as:
- It redirects all emails to single mailbox
- It even inserts X-original-to,bcc,cc headers to know the intended recipient of the mails

However, now developers are asking that it would be so good if on top of this I were to attach the original recipients (cc and bcc included) into the subject of the mails, like so:

Code:
Subject: (to: originalto@foo.bar, original2to@foo.bar, cc: originalcc, bcc: originalbcc) --- Original Subject of the Mail
I have read formail doc but I still don't see how. Is there a way to do that with formail or some bash scripting perhaps?
 
Old 02-28-2008, 10:26 PM   #2
jgombos
Member
 
Registered: Jul 2003
Posts: 256

Rep: Reputation: 32
AFAIK, it's just the -A switch to append. You're already using it for the TO field, so I'm not sure why that didn't occurr to you.. maybe I'm misunderstanding what it does.
 
Old 02-29-2008, 02:48 AM   #3
Sheridan
Member
 
Registered: Aug 2007
Location: Hungary
Distribution: Fedora, CentOS
Posts: 89

Original Poster
Rep: Reputation: 21
Quote:
Originally Posted by jgombos View Post
AFAIK, it's just the -A switch to append. You're already using it for the TO field, so I'm not sure why that didn't occurr to you.. maybe I'm misunderstanding what it does.
You are right - but my real problem is: How do I reference to the original values of "to", "cc", etc. inside -A ?

Like: -A "Subject: $to, $cc ..." or -A cc." - ".to." - ...", or how? The point is that I need to include the original recipients in the subject line, not just the header (that's working already).

Ok I'm obviously using this tool for the first time so I maybe missing some very trivial thing. But still...

Last edited by Sheridan; 02-29-2008 at 02:50 AM.
 
Old 02-29-2008, 09:33 AM   #4
jgombos
Member
 
Registered: Jul 2003
Posts: 256

Rep: Reputation: 32
This is how I think it might be done (untested):

formail -A "Subject: (to: $(formail -x To: <filename>))"

That only uses the To field to keep the example simple. I'm guessing that both instances of formail can't use stdin. I'm uncertain, but <filename> could perhaps be /dev/stdin if you want to try it.

Also, I used $(formail...) for command substitution. Alternatively, ticks would work too: eg. `formail...`

Last edited by jgombos; 02-29-2008 at 09:35 AM.
 
  


Reply

Tags
redirect, rewrite, sendmail


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
formail fails on virtual user [qmail,vpopmail,procmail,formail] jonavogt Linux - Networking 2 01-15-2009 10:29 AM
How to make sendmail logs e-mail subject? batbayar Linux - Server 0 05-08-2007 01:30 AM
Sending mail with subject in Linux script 151803 Linux - General 5 01-25-2007 05:46 AM
Piping to mail and adding a subject line. Echo Kilo Linux - General 1 12-03-2005 12:24 PM
How do I enter a subject when awk | data to mail 360 Programming 3 05-06-2002 09:22 PM


All times are GMT -5. The time now is 03:00 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
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration