This time with the patch...

On Fri 14/Dec/2012 13:03:50 +0100 Sam Varshavchik wrote:
> Alessandro Vesely writes:
>> On Fri 14/Dec/2012 01:01:23 +0100 Sam Varshavchik wrote:
>>> Alessandro Vesely writes:
>>>
>>>>   From: <u...@example.com>
>>>>   To: <l...@example.org>
>>>>
>>>> get changed to:
>>>>
>>>>   From: u...@example.com
>>>>   To: l...@example.org
>>>>
>>
>> After looking a bit closer at the code, I think I could
>> try a patch, next week, say.  How about NOADDRTRANSCRIBE?
> 
> Try it; not sure about the name, NOADDRREWRITE sounds better.

Sure, I just tried to avoid a the double 'R'...

I see no other reason than DKIM signatures to avoid rewriting those
lines.  The assumption that zdkimfilter makes, that incoming mail can
be signed while outgoing mail is not, does not have to be true in
general.  For example, a relay can use a smarthost with SMTP AUTH and
submit DKIM-signed mail.  So I allowed three values to NOADDRREWRITE:
never, always, and depending on the presence of a signature.

I tested submission works as expected.  I also patched esmtpd*.dist,
but did not test install-configure, nor the web config.

For readability, the large hunk that ends the patch, @@ -1811,33
+1822,40 @@, would have been two small hunks using "diff -wu":

@@ -1811,6 +1822,12 @@
          headername == "reply-to" ||
          headername == "sender")
       {
+         // The signature SHOULD be prepended to the message.
+
+         if (noaddrrewrite > 1)
+            noaddrrewrite = 0;
+         if (!noaddrrewrite)
+         {
       char   *errmsg;
       char   *new_header=rw_rewrite_header(mf->module,
                         header.c_str(),
@@ -1839,6 +1856,7 @@
             free(new_header);
             header += '\n';
          }
+         }
          if (headername == "from" &&
              !bofh_checkspf("BOFHSPFFROM", "off", "off"))
          {

Is that ok?
--- ./courier/module.local/localmail.orig.c     2012-04-22 16:05:29.000000000 
+0200
+++ ./courier/module.local/localmail.c  2012-12-17 16:26:12.000000000 +0100
@@ -319,8 +319,9 @@
        static const char *envvars[]={
                "DSNNOTIFY",
                "DSNRET",
-               "NOADDATE",
+               "NOADDDATE",
                "NOADDMSGID",
+               "NOADDRREWRITE",
                "MIME",
                0};
 
--- ./courier/doc/layout.orig.html      2011-04-04 16:47:58.000000000 +0200
+++ ./courier/doc/layout.html   2012-12-17 16:41:08.000000000 +0100
@@ -228,6 +228,10 @@
   <p><code>NOADDDATE</code> - if set, submit will not add a
   <code>Date:</code> header, if the message doesn't have it.</p>
 
+  <p><code>NOADDRREWRITE</code> - if set, submit will not rewrite any
+  <code>From:</code>, <code>To:</code>, and <code>Cc:</code> header, or check
+  whether the message has a <code>DKIM-Signature:</code> before doing so.</p>
+
   <p><code>SIZELIMIT</code> - maximum size of a message in bytes.
   Larger messages are rejected. If this environment variable is not
   set, <em>Courier</em> will read the <code>control/sizelimit</code> file.
--- ./courier/doc/submit.orig.html.in   2012-04-21 04:12:09.000000000 +0200
+++ ./courier/doc/submit.html.in        2012-12-17 16:51:11.000000000 +0100
@@ -160,7 +160,13 @@
 <code class="literal">Message-Id:</code> header to the message, if it does not 
have it.
 If this environment variable is set, the
 <span class="application">Courier</span> mail server will not add a
-<code class="literal">Message-Id:</code> header.</p></dd><dt><span 
class="term">MIME</span></dt><dd><p>
+<code class="literal">Message-Id:</code> header.</p></dd><dt><span 
class="term">NOADDRREWRITE</span></dt><dd><p>
+Normally the <span class="application">Courier</span> mail server rewrites 
addresses in the
+<code class="literal">From:</code>, <code class="literal">To:</code>, <code 
class="literal">Cc:</code> header fields.
+If this environment variable is set to <code class="literal">1</code>, the
+<span class="application">Courier</span> mail server will not rewrite them.  
If it is set to a higher value,
+the <span class="application">Courier</span> mail server will only rewrite it 
if no
+<code class="literal">DKIM-Signature:</code> header field was 
found.</p></dd><dt><span class="term">MIME</span></dt><dd><p>
 Normally the <span class="application">Courier</span> mail server
 adds any missing
 RFC2045 headers to the message. The <code class="envar">MIME</code> 
environment variable
--- ./courier/module.esmtp/esmtpd-ssl.orig.dist.in      2012-06-22 
14:20:44.000000000 +0200
+++ ./courier/module.esmtp/esmtpd-ssl.dist.in   2012-12-17 16:36:10.000000000 
+0100
@@ -65,6 +65,13 @@
 
 NOADDDATE=1
 
+##NAME: NOADDRREWRITE:0
+#
+# Don't rewrite To:, From:, and Cc: headers.  Set to 2 in order to omit
+# rewriting them only if there is a DKIM-Signature.
+
+NOADDRREWRITE=0
+
 ##NAME: ESMTP_LOG_DIALOG:0
 #
 #  If set, log the esmtp dialog.
--- ./courier/module.esmtp/esmtpd.orig.dist.in  2011-04-11 13:01:33.000000000 
+0200
+++ ./courier/module.esmtp/esmtpd.dist.in       2012-12-17 16:35:51.000000000 
+0100
@@ -72,6 +72,13 @@
 
 NOADDDATE=1
 
+##NAME: NOADDRREWRITE:0
+#
+# Don't rewrite To:, From:, and Cc: headers.  Set to 2 in order to omit
+# rewriting them only if there is a DKIM-Signature.
+
+NOADDRREWRITE=0
+
 ##NAME: ESMTP_LOG_DIALOG:0
 #
 #  If set, log the esmtp dialog.
--- ./courier/module.esmtp/esmtpd-msa.orig.dist.in      2011-04-04 
15:01:20.000000000 +0200
+++ ./courier/module.esmtp/esmtpd-msa.dist.in   2012-12-17 16:35:19.000000000 
+0100
@@ -38,6 +38,13 @@
 
 NOADDDATE=0
 
+##NAME: NOADDRREWRITE:0
+#
+# Don't rewrite To:, From:, and Cc: headers.  Set to 2 in order to omit
+# rewriting them only if there is a DKIM-Signature.
+
+NOADDRREWRITE=0
+
 ##NAME: ESMTP_LOG_DIALOG:0
 #
 #  If set, log the esmtp dialog.
--- ./courier/submit.orig.C     2012-04-25 05:12:35.000000000 +0200
+++ ./courier/submit.C  2012-12-17 16:26:04.000000000 +0100
@@ -1573,8 +1573,16 @@
        size_t  headercnt=500;
        size_t  headerlimit=100000;
        std::string::iterator line_iter;
+       int     noaddrrewrite=0;
        const   char *p;
 
+       p=getenv("NOADDRREWRITE");
+
+       if (p)
+       {
+               noaddrrewrite=atoi(p);
+       }
+
        p=getenv("BOFHHEADERLIMIT");
 
        if (p)
@@ -1733,6 +1741,9 @@
                               std::ptr_fun(::tolower));
 
                if (headername == "received")   ++received_cnt;
+               
+               else if (noaddrrewrite > 1 && headername == "dkim-signature")
+                       noaddrrewrite = 1;
 
                //
                // If no receipient were listed, grab them from the header.
@@ -1811,33 +1822,40 @@
                        headername == "reply-to" ||
                        headername == "sender")
                {
-               char    *errmsg;
-               char    *new_header=rw_rewrite_header(mf->module,
-                                                     header.c_str(),
-                                                     RW_HEADER|RW_SUBMIT,
-                                                     addresst, &errmsg);
+                       // The signature SHOULD be prepended to the message.
 
-                       if (!new_header)
+                       if (noaddrrewrite > 1)
+                               noaddrrewrite = 0;
+                       if (!noaddrrewrite)
                        {
-                               accumulated_errmsg += errmsg;
-                               free(errmsg);
-                       }
-                       else
-                       {
-                       const char *p;
-                       char    *q;
+                       char    *errmsg;
+                       char    *new_header=rw_rewrite_header(mf->module,
+                                                             header.c_str(),
+                                                             
RW_HEADER|RW_SUBMIT,
+                                                             addresst, 
&errmsg);
 
-                               header="";
-                               p=" ";
-                               for (q=new_header; (q=strtok(q, "\n")) != 0;
-                                       q=0)
+                               if (!new_header)
                                {
-                                       header += p;
-                                       header += q;
-                                       p="\n    ";
+                                       accumulated_errmsg += errmsg;
+                                       free(errmsg);
+                               }
+                               else
+                               {
+                               const char *p;
+                               char    *q;
+
+                                       header="";
+                                       p=" ";
+                                       for (q=new_header; (q=strtok(q, "\n")) 
!= 0;
+                                               q=0)
+                                       {
+                                               header += p;
+                                               header += q;
+                                               p="\n    ";
+                                       }
+                                       free(new_header);
+                                       header += '\n';
                                }
-                               free(new_header);
-                               header += '\n';
                        }
                        if (headername == "from" &&
                            !bofh_checkspf("BOFHSPFFROM", "off", "off"))
------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
courier-users mailing list
courier-users@lists.sourceforge.net
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users

Reply via email to