LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   procmail; recipe help; returning notification on overly large emails (https://www.linuxquestions.org/questions/programming-9/procmail%3B-recipe-help%3B-returning-notification-on-overly-large-emails-305122/)

TheLinuxDuck 03-23-2005 12:05 PM

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!

TheLinuxDuck 03-25-2005 04:32 PM

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!!

juan1987 02-05-2010 01:28 AM

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 ??


All times are GMT -5. The time now is 07:44 PM.