LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-23-2005, 01:05 PM   #1
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
procmail; recipe help; returning notification on overly large emails


Ok, here's the scoop. Our mail server is older and doesn't handle large file attaches well. We're working on replacing it, but it will take some time... anyway, in the mean time, we're basically rejecting any emails over 5meg (which roughly translates to about 7meg after uuencoding).

Here is the procmail recipe:
Code:
:0
* > 7000000
* !^FROM_DAEMON
* !^X-Loop: ourdomain.com
{
  LOG="Reason: Message over 5meg in size. Refusing
"
  :0 c: toolarge.lock
  | (/usr/bin/formail -r -A "X-Loop: ourdomain.com"; cat /etc/messagetoobig.txt) | $S
ENDMAIL -t -frejection_notice

  :0:
  /dev/null
}
The recipe we're using works. If the incoming email is larger than 7meg, it is deleted, and the warning message, stored in /etc/messagetoobig.txt, is emailed to them.

However, the procmail log file records an error, saying that there was an error writing to the given sendmail command:
Code:
For: realusername
Reason: Message over 5meg in size. Refusing
procmail: Error while writing to " (/usr/bin/formail -r -A "X-Loop: ourdomain.com"; cat /etc/messagetoobig.txt) | $SENDMAIL -t -frejection_notice"
From realperson@theirdomain.com  Tue Mar 22 12:13:09 2005
 Subject: FW: RFI'S
  Folder: /dev/null             7486351
I've tried everything of which I can think, and cannot figure out why this sucker is giving this error.

Anyone have any ideas?

Also, is there a way to make sendmail reject files over a certain size, while also returning an error email to the sender? That would save me some processing time.

I'd appreciate any help!
 
Old 03-25-2005, 05:32 PM   #2
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Original Poster
Rep: Reputation: 33
Ok, so there are no procmail recipe nerds here, eh? That's ok.. I ended up asking this question on the procmail mailing list, and received very adequate answers. Here is what was learned:
Code:
  :0 c: toolarge.lock
Issue #1: The filelocking is unnecessary.
Why: The email is never sent to a file nor mailbox. No need to lock anything.

Issue #2: The carbon copy is unecessary.
Why: Once the email is sent to sendmail/formail, the rule does not need to send the email to /dev/null, because it's already been dealt with. This will only produce wasted processing time.

Issue #3: The 'h' header-only flag is needed.
Why: Without it, the entire email, header and body, are being sent to formail, causing a delay as the emails-in-question are over 5meg in size. Formail only handles the header, and stops accepting input once the header receipt is complete. Procmail then sees that the entire email was not read, and triggers an error. This is why I was getting an error in my log file.

Final line should be:
Code:
:0 h
Next segment:
Code:
  | (/usr/bin/formail -r -A "X-Loop: ourdomain.com"; \
    cat /etc/messagetoobig.txt) | $SENDMAIL -t -frejection_notice
Issue #1: Full path to formail is unnecessary.
Why: The build-in path's will locate the binary. It doesn't hurt to have it, but it is not necessary.

Issue #2: $SENDMAIL is missing $SENDMAILFLAGS.
Why: Honestly, I don't know how necessary this is. (=

Final line should be:
Code:
  | (formail -r -A "X-Loop: ourdomain.com"; \
    cat /etc/messagetoobig.txt) \
    | $SENDMAIL $SENDMAILFLAGS -t -frejection_notice

And finally:
Code:
  
  :0:
  /dev/null
Issue #1: Filelocking on /dev/null is unnecessary.
Why: Race conditions cannot exist on a device that cannot return anything.

Issue #2: Whole rule is unnecessary.
Why: Without the 'c' carbon-copy flag, this rule is no needed. Delete it.

In the end, we end up looking like this:
Code:
:0
* > 7000000
* !^FROM_DAEMON
* !^X-Loop: ourdomain.com
{
  LOG="Reason: Message over 5meg in size. Refusing
"
  :0 h
    | (formail -r -A "X-Loop: ourdomain.com"; \
      cat /etc/messagetoobig.txt) \
      | $SENDMAIL $SENDMAILFLAGS -t -frejection_notice
}
And no error message! Yay!!
 
Old 02-05-2010, 02:28 AM   #3
juan1987
LQ Newbie
 
Registered: Oct 2008
Distribution: Suse, Red Hat
Posts: 13

Rep: Reputation: 0
Hi

Just read your post i'm trying to do the exact same thing using sendmail.
I was just wondering if you ever found out how to do this with sendmail ??
 
  


Reply


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
Three actions in a recipe of Procmail Borelian Linux - Software 1 11-11-2012 07:48 AM
what is wrong with this regular expression in procmail recipe? realos Linux - Software 4 10-20-2005 10:35 AM
Procmail recipe jebix666 Linux - General 1 06-09-2005 02:43 PM
procmail recipe for charset conversion Peff Linux - Software 0 07-13-2004 03:40 AM
procmail recipe not working? theLIGHT Linux - Software 3 11-18-2002 11:04 PM


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