Re: [Mimedefang] conditionally add boilerplate in message with more than one recipient
> From: "Richard Laager" >> OK, got it. However, I want all the filtering stuff in the filter*() >> functions to be applied to the "resent" message to ORG, except the >> boilerplate. I guess it's not >> possible because resend_message resends the ORIGINAL message and won't be >> processed. >> > When the message is resent, you'll see it again in another run of the > filter. That's your opportunity to do what you need for the ORG > recipient. Craft your filter very careful in light of this! I'm sorry but I'm obviously doing something wrong but just don't know what. I'm not seeing the message again in another run of the filter. I did a simple test such as: sub filter_end { my($entity) = @_; my($d1) = scalar(@Recipients); my($d2) = $Recipients[0]; my($d3) = ""; if (scalar(@Recipients) == 2) { $d3 = $Recipients[1]; } md_syslog('info', "debug_resendmsg_d1_${d1}_${Subject}"); md_syslog('info', "debug_resendmsg_d2_${d2}_${Subject}"); md_syslog('info', "debug_resendmsg_d3_${d3}_${Subject}"); if ($d1 == 2 && $d2 eq '' && $d3 eq '') { <-->md_syslog('info', "debug_resendmsg_match_${Subject}"); <-->if (resend_message($d3)) { <-->delete_recipient($d3); <-->md_syslog('info', "debug_resendmsg_resent_and_deleted_$d3"); <-->} } [continues...] I then sent an email to "u...@domain.com, u...@domain.org", grepped the log and found: # tail -n 1 /var/log/messages | grep debug_resendmsg mimedefang.pl[16650]: DFB4B35E3265: debug_resendmsg_d1_2_test 1 mimedefang.pl[16650]: DFB4B35E3265: debug_resendmsg_d2__test 1 mimedefang.pl[16650]: DFB4B35E3265: debug_resendmsg_d3__test 1 mimedefang.pl[16650]: DFB4B35E3265: debug_resendmsg_match_test 1 mimedefang.pl[16858]: DFB4B35E3265: debug_resendmsg_sendmail: /usr/sbin/sendmail -f -odd -Ac -oi -- mimedefang.pl[16650]: DFB4B35E3265: debug_resendmsg_resent_and_deleted_ If I remove the custom "if" clause from filter_end() and send another e-mail then this is what I get in the log (no call to resend_message): mimedefang.pl[22093]: 7274235E33E7: debug_resendmsg_d1_2_test 2 mimedefang.pl[22093]: 7274235E33E7: debug_resendmsg_d2__test 2 mimedefang.pl[22093]: 7274235E33E7: debug_resendmsg_d3__test 2 So since I'm getting the same number of lines on the log regarding "debug_resendmsg_d{1,2,3}" then I'm assuming I'm getting just one run through the filter. BTW I also tried running this command manually and it worked fine (I could send an e-mail correctly): /usr/sbin/sendmail -f -odd -Ac -oi -- Like I said before, I'm using Postfix but the sendmail interface seems to work fine. What am I doing wrong? Vieri ___ NOTE: If there is a disclaimer or other legal boilerplate in the above message, it is NULL AND VOID. You may ignore it. Visit http://www.mimedefang.org and http://www.roaringpenguin.com MIMEDefang mailing list MIMEDefang@lists.roaringpenguin.com http://lists.roaringpenguin.com/mailman/listinfo/mimedefang
Re: [Mimedefang] conditionally add boilerplate in message with more than one recipient
On 09/22/2016 11:54 AM, Vieri Di Paola wrote: >> From: "Richard Laager" >>> It's a typo, I presume? In my example, u...@domain.com wants the >>> boilerplate and u...@domain.org doesn't. So I guess you meant "resend to >>> u...@domain.com, >>> delete_recipient(u...@domain.org) and add boilerplate", right? >> >> No, I don't think so? If ORG does NOT WANT boilerplate, then you resend >> to ORG and delete ORG, as resending sends the original, unmodified, no >> boilerplate message. Then you add boilerplate for the remaining >> recipient, which is COM, who WANTS the boilerplate. > > OK, got it. However, I want all the filtering stuff in the filter*() > functions to be applied to the "resent" message to ORG, except the > boilerplate. I guess it's not possible because resend_message resends the > ORIGINAL message and won't be processed. When the message is resent, you'll see it again in another run of the filter. That's your opportunity to do what you need for the ORG recipient. Craft your filter very careful in light of this! -- Richard ___ NOTE: If there is a disclaimer or other legal boilerplate in the above message, it is NULL AND VOID. You may ignore it. Visit http://www.mimedefang.org and http://www.roaringpenguin.com MIMEDefang mailing list MIMEDefang@lists.roaringpenguin.com http://lists.roaringpenguin.com/mailman/listinfo/mimedefang
Re: [Mimedefang] conditionally add boilerplate in message with more than one recipient
> From: "Richard Laager" >> It's a typo, I presume? In my example, u...@domain.com wants the boilerplate >> and u...@domain.org doesn't. So I guess you meant "resend to >> u...@domain.com, >> delete_recipient(u...@domain.org) and add boilerplate", right? > > No, I don't think so? If ORG does NOT WANT boilerplate, then you resend > to ORG and delete ORG, as resending sends the original, unmodified, no > boilerplate message. Then you add boilerplate for the remaining > recipient, which is COM, who WANTS the boilerplate. OK, got it. However, I want all the filtering stuff in the filter*() functions to be applied to the "resent" message to ORG, except the boilerplate. I guess it's not possible because resend_message resends the ORIGINAL message and won't be processed. ___ NOTE: If there is a disclaimer or other legal boilerplate in the above message, it is NULL AND VOID. You may ignore it. Visit http://www.mimedefang.org and http://www.roaringpenguin.com MIMEDefang mailing list MIMEDefang@lists.roaringpenguin.com http://lists.roaringpenguin.com/mailman/listinfo/mimedefang
Re: [Mimedefang] conditionally add boilerplate in message with more than one recipient
On 09/21/2016 05:13 PM, Vieri Di Paola wrote: >> From: "Richard Laager" >> So in your case, you would resent to u...@domain.org, >> delete_recipient(u...@domain.org), and then add the boilerplate. > > It's a typo, I presume? In my example, u...@domain.com wants the boilerplate > and u...@domain.org doesn't. So I guess you meant "resend to u...@domain.com, > delete_recipient(u...@domain.org) and add boilerplate", right? No, I don't think so? If ORG does NOT WANT boilerplate, then you resend to ORG and delete ORG, as resending sends the original, unmodified, no boilerplate message. Then you add boilerplate for the remaining recipient, which is COM, who WANTS the boilerplate. -- Richard ___ NOTE: If there is a disclaimer or other legal boilerplate in the above message, it is NULL AND VOID. You may ignore it. Visit http://www.mimedefang.org and http://www.roaringpenguin.com MIMEDefang mailing list MIMEDefang@lists.roaringpenguin.com http://lists.roaringpenguin.com/mailman/listinfo/mimedefang
Re: [Mimedefang] conditionally add boilerplate in message with more than one recipient
> From: "Richard Laager" > So in your case, you would resent to u...@domain.org, > delete_recipient(u...@domain.org), and then add the boilerplate. It's a typo, I presume? In my example, u...@domain.com wants the boilerplate and u...@domain.org doesn't. So I guess you meant "resend to u...@domain.com, delete_recipient(u...@domain.org) and add boilerplate", right? The man page says to call this function (resend_message) in either filter_begin() or filter_end(). The *boilerplate* functions can only be called in filter_end(). I haven't tried it yet but would it look something like this pseudo-code below? sub filter_end() { @want_boilerplate = get_recipients_with_boilerplate_from(@Recipients); @dont_want_boilerplate = get_recipients_without_boilerplate_from(@Recipients); if (scalar(@dont_want_boilerplate) > 0 && resend_message(@want_boilerplate)) { foreach $recip (@dont_want_boilerplate) { delete_recipient($recip); } append_text_boilerplate(); append_html_boilerplate(); } [continue with other filtering code in this function...] Sorry if I only have a vague idea of how the mimedefang filtering process works but I don't know if the new ORIGINAL message created by resend_message will also go through the filter_begin(), filter() and filter_end() functions again. That's because I have other filtering needs in those functions not just appending a boilerplate (such as virus scanning, etc). In other words, I need ALL messages to be processed via all filter*() functions and SOME messages sent to specific recipients should not have a boilerplate appended. So does the filtering process start over again with resend_message()? Finally, I'm using Postfix 3.1.0 with mimedefang and it's working fine. However, I'm concerned that resend_message() might not work as expected since the man page only refers to Sendmail-specific flags. Thanks, Vieri ___ NOTE: If there is a disclaimer or other legal boilerplate in the above message, it is NULL AND VOID. You may ignore it. Visit http://www.mimedefang.org and http://www.roaringpenguin.com MIMEDefang mailing list MIMEDefang@lists.roaringpenguin.com http://lists.roaringpenguin.com/mailman/listinfo/mimedefang
Re: [Mimedefang] conditionally add boilerplate in message with more than one recipient
On 09/21/2016 09:09 AM, Vieri Di Paola wrote: >> You can stream_by_recipient() so MIMEDefang resends the message for each >> recipient. In this way, your filter code can handle recipients >> differently. Note the warnings in the mimedefang-filter man page, though. > > The man page isn't too extensive on this. At a first glance it seems that > calling stream_by_recipient in filter_begin does not trigger the code in > filter_end, for instance. So if stream_by_recipient is true then only > filter() is run? I don't use stream_by_recipient() and never have. Here's my understanding, though... If stream_by_recipient() returns false, there was only one user, so stream_by_recipient() did nothing and the filter runs as normal. If there are multiple recipients, then stream_by_recipient() resends the original message to each recipient individually, and your filter should terminate. You'll then see the new messages in separate invocations of your filter. >> Alternatively, you can do all the work yourself, and only selectively >> resend when necessary. This is what I do (not for boilerplate insertion, >> but other things). > > How do you do that? > Do you use resend_message()? (but that resends immediately the ORIGINAL > message) Until a few weeks ago, yes. We were adding a header in some cases. So what we did was: if everyone wants the header, add it, and we're done. If some recipients want the header and some don't, resend the (original) message to those who *don't*, remove them with delete_recipient(), and add the header. So in your case, you would resent to u...@domain.org, delete_recipient(u...@domain.org), and then add the boilerplate. We're now doing more extensive modifications, so I have re-implemented resend_message() with my own code to modify the message as appropriate. -- Richard ___ NOTE: If there is a disclaimer or other legal boilerplate in the above message, it is NULL AND VOID. You may ignore it. Visit http://www.mimedefang.org and http://www.roaringpenguin.com MIMEDefang mailing list MIMEDefang@lists.roaringpenguin.com http://lists.roaringpenguin.com/mailman/listinfo/mimedefang
Re: [Mimedefang] conditionally add boilerplate in message with more than one recipient
Thanks Richard. > Sent: Wednesday, September 21, 2016 at 2:44 PM > From: "Richard Laager" > To: mimedefang@lists.roaringpenguin.com > Subject: Re: [Mimedefang] conditionally add boilerplate in message with more > than one recipient > On 09/21/2016 07:16 AM, Vieri Di Paola wrote: >> Suppose I have an email that's being sent To: u...@domain.org, >> u...@domain.com. >> >> @Recipients will hold both addresses. >> I'd like mimedefang to add a boilerplate only for the message being sent to >> u...@domain.com. >> >> Is that possible? >> If so, how? > > You can stream_by_recipient() so MIMEDefang resends the message for each > recipient. In this way, your filter code can handle recipients > differently. Note the warnings in the mimedefang-filter man page, though. The man page isn't too extensive on this. At a first glance it seems that calling stream_by_recipient in filter_begin does not trigger the code in filter_end, for instance. So if stream_by_recipient is true then only filter() is run? > Alternatively, you can do all the work yourself, and only selectively > resend when necessary. This is what I do (not for boilerplate insertion, > but other things). How do you do that? Do you use resend_message()? (but that resends immediately the ORIGINAL message) Vieri ___ NOTE: If there is a disclaimer or other legal boilerplate in the above message, it is NULL AND VOID. You may ignore it. Visit http://www.mimedefang.org and http://www.roaringpenguin.com MIMEDefang mailing list MIMEDefang@lists.roaringpenguin.com http://lists.roaringpenguin.com/mailman/listinfo/mimedefang
Re: [Mimedefang] conditionally add boilerplate in message with more than one recipient
On 09/21/2016 07:16 AM, Vieri Di Paola wrote: > Suppose I have an email that's being sent To: u...@domain.org, > u...@domain.com. > > @Recipients will hold both addresses. > I'd like mimedefang to add a boilerplate only for the message being sent to > u...@domain.com. > > Is that possible? > If so, how? You can stream_by_recipient() so MIMEDefang resends the message for each recipient. In this way, your filter code can handle recipients differently. Note the warnings in the mimedefang-filter man page, though. Alternatively, you can do all the work yourself, and only selectively resend when necessary. This is what I do (not for boilerplate insertion, but other things). -- Richard ___ NOTE: If there is a disclaimer or other legal boilerplate in the above message, it is NULL AND VOID. You may ignore it. Visit http://www.mimedefang.org and http://www.roaringpenguin.com MIMEDefang mailing list MIMEDefang@lists.roaringpenguin.com http://lists.roaringpenguin.com/mailman/listinfo/mimedefang
[Mimedefang] conditionally add boilerplate in message with more than one recipient
Hi, Suppose I have an email that's being sent To: u...@domain.org, u...@domain.com. @Recipients will hold both addresses. I'd like mimedefang to add a boilerplate only for the message being sent to u...@domain.com. Is that possible? If so, how? I can only add boilerplates in filter_end but not in filter_recipient. However, I can tell which is the "current" recipient being processed in filter_recipient but not in filter_end. I guess it's not designed to do this unless I somehow duplicate the message itself and add a boilerplate to one of the two. Thanks, Vieri ___ NOTE: If there is a disclaimer or other legal boilerplate in the above message, it is NULL AND VOID. You may ignore it. Visit http://www.mimedefang.org and http://www.roaringpenguin.com MIMEDefang mailing list MIMEDefang@lists.roaringpenguin.com http://lists.roaringpenguin.com/mailman/listinfo/mimedefang