Update of /cvsroot/tmda/tmda/bin
In directory usw-pr-cvs1:/tmp/cvs-serv9086/bin

Modified Files:
        ChangeLog tmda-rfilter 
Log Message:
* Auto responder improvements:

- Auto responses are now MIME messages with one or two bodyparts,
depending on the value of AUTORESPONSE_INCLUDE_SENDER_COPY.

- Character sets other than US-ASCII in the templates are now
supported.  This includes multi-byte character sets such as those
found in Asian languages.  RFC-compliant charset conversion and 7-bit
transport encoding will be handled automatically by the auto
responder.

The default charset for the message body is US-ASCII, and can be
changed by editing `BodyCharset:' in your template.

- Multilingual header values are now supported, and likewise, this
includes multi-byte character sets.  The RFC 2047 encoding is handled
by the auto-responder.

The default charset for each header generated from a template is
US-ASCII.  You can change this by editing the .CHARSET suffix of each
header definition.  For example:

  Subject.US-ASCII: Please confirm your message

might be changed to 

  Subject.Latin-1: German translation here

if you wish to use German umlauts in your Subject field.

- The `Auto-Submitted:' header described in Keith Moore's IETF draft
``Recommendations for Automatic Responses to Electronic Mail''
(draft-moore-auto-email-response-00.txt) is supported.  This header is
checked when receiving incoming messages, and also added to TMDA's own
auto responses.


Index: ChangeLog
===================================================================
RCS file: /cvsroot/tmda/tmda/bin/ChangeLog,v
retrieving revision 1.236
retrieving revision 1.237
diff -u -r1.236 -r1.237
--- ChangeLog   4 Oct 2002 23:43:32 -0000       1.236
+++ ChangeLog   18 Oct 2002 22:36:16 -0000      1.237
@@ -1,3 +1,9 @@
+2002-10-18  Jason R. Mastaler  <[EMAIL PROTECTED]>
+
+       * tmda-rfilter (autorespond_to_sender): Check for Auto-Submitted:.
+
+       (send_bounce): Move guts into TMDA/AutoResponse.py.
+
 2002-10-04  Jason R. Mastaler  <[EMAIL PROTECTED]>
 
        * tmda-inject (inject_message): Use MESSAGE_TAG_HEADER_STYLE when

Index: tmda-rfilter
===================================================================
RCS file: /cvsroot/tmda/tmda/bin/tmda-rfilter,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -r1.68 -r1.69
--- tmda-rfilter        30 Sep 2002 23:45:54 -0000      1.68
+++ tmda-rfilter        18 Oct 2002 22:36:16 -0000      1.69
@@ -277,20 +277,6 @@
         logger.write()
 
 
-def normalize_sender(sender):
-    """Return a normalized version of the given sender address for use
-    in ~/.tmda/responses.
-
-    - Any / characters are replaced with : to prevent creation of files
-      outside the directory.
-    - Spaces are replaced with underscores.
-    - The address is lowercased.
-    """
-    sender = sender.replace(' ', '_')
-    sender = sender.replace('/', ':')
-    return sender.lower()
-
-
 def autorespond_to_sender(sender):
     """Return true if TMDA should auto-respond to this sender."""
     # Try and detect a bounce message.
@@ -299,6 +285,13 @@
            envelope_sender.lower().startswith('mailer-daemon'):
         logit ('DROP (envelope sender = %s)' % envelope_sender)
         return 0
+    # Try and detect an auto-response.
+    guilty_header = None
+    auto_submitted = msgin.get('auto-submitted')
+    if auto_submitted:
+        if auto_submitted.lower().strip().startswith('auto-generated') or \
+               auto_submitted.lower().strip().startswith('auto-replied'):
+            guilty_header = 'Auto-Submitted: %s' % auto_submitted
     # Try and detect a mailing list message.
     #   - header "List-ID:" (as per RFC 2919)
     #   - header "Mailing-List:"
@@ -306,22 +299,21 @@
     #   - header "X-ML-Name:"
     #   - header "List-(Help|Unsubscribe|Subscribe|Post|Owner|Archive):"
     #     (as per RFC 2369)
-    guilty_header = None
-    list_headers = ['List-Id', 'List-Help', 'List-Subscribe',
-                    'List-Unsubscribe', 'List-Post', 'List-Owner',
-                    'List-Archive', 'Mailing-List', 'X-Mailing-List',
-                    'X-Ml-Name']
-    for hdr in list_headers:
-        if msgin.has_key(hdr):
-            guilty_header = '%s: %s' % (hdr, msgin.get(hdr))
+    if guilty_header is None:
+        list_headers = ['List-Id', 'List-Help', 'List-Subscribe',
+                        'List-Unsubscribe', 'List-Post', 'List-Owner',
+                        'List-Archive', 'Mailing-List', 'X-Mailing-List',
+                        'X-Ml-Name']
+        for hdr in list_headers:
+            if msgin.has_key(hdr):
+                guilty_header = '%s: %s' % (hdr, msgin.get(hdr))
     #   - header "Precedence:" value junk, bulk, or list
-    precedence = msgin.get('precedence')
-    if precedence and \
-           precedence.lower() in ('bulk', 'junk', 'list') and \
-           guilty_header is None:
-        guilty_header = 'Precedence: %s' % precedence
+    if guilty_header is None:
+        precedence = msgin.get('precedence')
+        if precedence and precedence.lower() in ('bulk', 'junk', 'list'):
+            guilty_header = 'Precedence: %s' % precedence
     if guilty_header:
-        logit ('DROP (%s)' % guilty_header)
+        logit ('NOREPLY (%s)' % guilty_header)
         return 0
     # Auto-response rate limiting.  Algorithm based on Bruce Guenter's
     # qmail-autoresponder (http://untroubled.org/qmail-autoresponder/).
@@ -351,55 +343,25 @@
                 sndrlist.append(address)
         # Count remaining occurrences of this sender, and don't
         # respond if that number it exceeds our threshold.
-        if sndrlist.count(normalize_sender(sender)) >= \
+        if sndrlist.count(Util.normalize_sender(sender)) >= \
                Defaults.MAX_AUTORESPONSES_PER_DAY:
-            logit('DROP (%s = %s)' % ('MAX_AUTORESPONSES_PER_DAY',
-                                      Defaults.MAX_AUTORESPONSES_PER_DAY))
+            logit('NOREPLY (%s = %s)' % ('MAX_AUTORESPONSES_PER_DAY',
+                                         Defaults.MAX_AUTORESPONSES_PER_DAY))
             return 0
     return 1
 
 
-def send_bounce(bounce_message, **vars):
-    """Send a confirmation message back to the sender."""
+def send_bounce(bounce_message, type):
+    """Send a auto-response back to the envelope sender address."""
     if autorespond_to_sender(envelope_sender) and auto_reply:
-        bounce_msg = email.message_from_string(bounce_message)
-        # Add some headers.
-        timesecs = time.time()
-        bounce_msg['Date'] = Util.make_date(timesecs)
-        bounce_msg['Message-ID'] = Util.make_msgid(timesecs)
-        # References
-        refs = []
-        for h in ['references', 'message-id']:
-            if msgin.has_key(h):
-                refs = refs + msgin.get(h).split()
-        if refs:
-            bounce_msg['References'] = '\n\t'.join(refs)
-        # In-Reply-To
-        if msgin.has_key('message-id'):
-            bounce_msg['In-Reply-To'] =  msgin.get('message-id')
-        bounce_msg['To'] = envelope_sender
-        if not vars.has_key('already_confirmed'):
-            bounce_msg['Reply-To'] = vars['confirm_accept_address']
-        bounce_msg['Precedence'] = 'bulk'
-        bounce_msg['X-Delivery-Agent'] = 'TMDA/%s' % Version.TMDA
-        # Optionally, add some headers.
-        if Defaults.ADDED_HEADERS_SERVER:
-            for hdr in Defaults.ADDED_HEADERS_SERVER.keys():
-                del bounce_msg[hdr]
-                bounce_msg[hdr] = Defaults.ADDED_HEADERS_SERVER[hdr]
-        Util.sendmail(bounce_msg.as_string(),
-                      envelope_sender, Defaults.BOUNCE_ENV_SENDER)
+        from TMDA import AutoResponse
+        ar = AutoResponse.AutoResponse(msgin, bounce_message,
+                                       type, envelope_sender)
+        ar.create()
+        ar.send()
         # Optionally, record this auto-response.
         if Defaults.MAX_AUTORESPONSES_PER_DAY != 0:
-            response_filename = '%s.%s.%s' % (int(time.time()),
-                                              Defaults.PID,
-                                              normalize_sender(envelope_sender))
-            # Create ~/.tmda/responses if necessary.
-            if not os.path.exists(Defaults.RESPONSE_DIR):
-                os.makedirs(Defaults.RESPONSE_DIR, 0700)
-            fp = open(os.path.join(Defaults.RESPONSE_DIR,
-                                   response_filename), 'w')
-            fp.close()
+            ar.record()
 
 
 def send_cc(address):
@@ -633,6 +595,7 @@
     pending_contents = msgin.as_string()
     Util.writefile(pending_contents,
                    os.path.join(pendingdir, pending_message))
+    del msgin['X-TMDA-Recipient']
     return pending_message
 
 
@@ -650,14 +613,7 @@
     original_message_body = globals().get('orig_msgin_body_as_raw_string')
     original_message_headers = globals().get('orig_msgin_headers_as_raw_string')
     original_message_size = globals().get('orig_msgin_size')
-    # Don't include message bodies over a certain size.
-    if (Defaults.CONFIRM_MAX_MESSAGE_SIZE and
-        (int(Defaults.CONFIRM_MAX_MESSAGE_SIZE) < int(original_message_size))):
-        original_message = "%s\n[ Message body suppressed (exceeded %s bytes) ]"\
-                           % (original_message_headers,
-                              Defaults.CONFIRM_MAX_MESSAGE_SIZE)
-    else:
-        original_message = globals().get('orig_msgin_as_string')
+    original_message = globals().get('orig_msgin_as_string')
     # Optional 'dated' address variables.
     if Defaults.DATED_TEMPLATE_VARS:
         dated_timeout = Util.format_timeout(Defaults.TIMEOUT)
@@ -693,19 +649,18 @@
             send_cc(Defaults.CONFIRM_CC)
         logit("HOLD pending " + pending_message)
         mta.stop()
-
     # Create the confirm message and then send it.
     bounce_message = Util.maketext(templatefile, vars())
-    if mode in ('accept', 'bounce'):
-        send_bounce(bounce_message, already_confirmed=1)
-        if mode == 'bounce':
-            mta.stop()
+    if mode == 'accept':
+        send_bounce(bounce_message, mode)
+    elif mode == 'bounce':
+        send_bounce(bounce_message, mode)
+        mta.stop()
     elif mode == 'request':
         if Defaults.CONFIRM_CC:
             send_cc(Defaults.CONFIRM_CC)
         logit("CONFIRM pending " + pending_message)
-        send_bounce(bounce_message,
-                    confirm_accept_address = confirm_accept_address)
+        send_bounce(bounce_message, mode)
         mta.stop()     
 
 

_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs

Reply via email to