Attachment stripping - wrong postfix message size

Markus Nilsson markus at markusoft.se
Wed Mar 24 09:59:34 GMT 2010


On 23 March 2010 17:07, Markus Nilsson <markus at markusoft.se> wrote:
> Hi again,
>
> I've done a little bit of searching around in the source, enabled some debug prints etc, and can't find anywhere that the C-record metadata read from the original queuefile is edited. Am I missing something here, or is MailScanner ignoring any changes made to the mail in respect to size, and just lets the queue file keep its original C record?
>
> I would really need my postfix instance to give a correct estimation of the message size to the receiving mailserver when starting delivert since I am stripping away any large attachments, and the mails are quite smaller after being processed by MS!
>
>
> /BR
> Markus

Hej Markus,

Well... you might be right about the size thing, I haven't revisited
that part in a while (and don't really have time to do so either,
sorry).
The thing that stikes me as somewhat odd though ... is why you would
want to do anything like this...? I've alwasy kept my "max sizes" in
sync, to the best of my ability. That way I never _need_ anything like
that, since I've already rejected any message violating the message
size limit.

That being said, it'd be a Good Thing if Jules could be persuaded to
take a look at the relevant code, or point you in the correct
direction (ie where the update of the C record is "hidden":-).

Cheers
-- 
-- Glenn



Hej Glenn!,

I want to do this because I don't reject the mail, I let it by with reduced 
size. I am then able to let the recipient download the attachment seperatley.
In that way the message get through, and the attachment is retrievable, even
if the recipient (a server out of my control) has rules that would reject large 
emails. But since it seems that my postfix instance believes that the email 
has the original size, it reports that size to the receiving mail server, 
which rejects it.

I'm now into the Postfix.pm code, the sub PreDataString. 

I have successfully changed the C record to use $message->{size} as the message_size,
but since the postfix queue file format is "intentionally undocumented" (sigh) it is
hard to realize if I have ruined something else, I'm by no means sure what all fields mean...

My code change, in Postfix.pm, PreDataString sub:

    foreach (@{$message->{metadata}}) {
      /^(.)(.*)$/;
      ($type, $data) = ($1, $2);
      $TimestampFound++ if $type eq 'T'; # Must only ever have 1 timestamp
      #print STDERR "PreData1 Type $type Data $data\n";
+      if($type eq 'C')
+      {
+        if ($data =~ m/(\D+)\d+(\D+\d+\D+\d+\D+\d+\D+)\d+/)
+        {
+          print STDERR "Size: " . $message->{size} . "\n";
+          print STDERR "Data: (" . $data . ")\n";
+          print STDERR "$1;$2;$3;$4\n";
+          print STDERR "" . $data ."\n";
+          $data = "" . $1 . $message->{size} . $2 . $message->{size};
+          print STDERR "" . $data . "\n";
+        }
+        else
+        {
+          print STDERR "No match (" . $data . ") Leaving as is\n";
+        }
      }

Please give me a hint if I should keep my hands off this code, or if this
could be safe. I'm thinking of setting a flag in the message struct to
tell if this change should be done or not, to only update the ones that 
really needs it.


BR/
Markus


> ----- Original Message -----
> From: "Markus Nilsson" <markus at markusoft.se>
> To: mailscanner at lists.mailscanner.info
> Sent: tisdag, 23 mar 2010 10:53:07
> Subject: Attachment stripping - wrong postfix message size
>
> Hi,
>
> I'm having a problem with a custom function for attachment stripping based on total attachment size. The custom function is made for
>
> Maximum Attachment Size =
>
> I successfully return 1 if the summed size of all attachments are larger than my configured value, and -1 otherwise. The custom function also stores the attachments in a safe place for later retrieval. I then want MailScanner/postifx to deliver the stripped mail to the recipient(s). MailScanner seems to do it right, but for some reason when postfix delivers the mail to the receiving mail server, it reports the message size as it was before the stripping, so that server might reject the mail even though it really isn't that big.
>
> If I configure the mailserver to accept larger sizes, the received mail has the correct size (small, all attachments stripped), so the reported size by postfix is not correct!
>
> Does postfix somehow approximate the message size?
> If so, is it possible to help postifix with this approximization?
> Or am I completely missing something else out?
>
> Any help greatly appreciated!
>
> BR
> Markus
>
>
> --
> MailScanner mailing list
> mailscanner at lists.mailscanner.info
> http://lists.mailscanner.info/mailman/listinfo/mailscanner
>
> Before posting, read http://wiki.mailscanner.info/posting
>
> Support MailScanner development - buy the book off the website!
>
>
>
> --
> MailScanner mailing list
> mailscanner at lists.mailscanner.info
> http://lists.mailscanner.info/mailman/listinfo/mailscanner
>
> Before posting, read http://wiki.mailscanner.info/posting
>
> Support MailScanner development - buy the book off the website!
>



-- 
-- Glenn
email: glenn < dot > steen < at > gmail < dot > com
work: glenn < dot > steen < at > ap1 < dot > se
--
MailScanner mailing list
mailscanner at lists.mailscanner.info
http://lists.mailscanner.info/mailman/listinfo/mailscanner

Before posting, read http://wiki.mailscanner.info/posting

Support MailScanner development - buy the book off the website!







More information about the MailScanner mailing list