[Mailman-Developers] Help on a code sample...

Donal Hunt donal.hunt2@mail.dcu.ie
Sun, 26 May 2002 16:55:42 +0100


Hi there,

I've written the following example handler for Mailman but have a bug
that I can't for the life of me understand why it's happening...  It's
based on Personalize.py (yes, I'm aware it's deprecated, but it works
for me. :-))

Basically.  The email gets encrypted correctly for the first person (and
sent to them), but the second person gets person one's mail encrypted!! 
Basically "valu"e doesn't get reset back to the actual unencrypted email
contents (msg).

I'm sure I'm missing something stupid in my loop (to do the multi-part
stuff).  If someone spots it I'ld really appreciate a mail.

Thanks in advance.

Donal
DCU

-----------------------------------------------------
def process(mlist, msg, msgdata):
    if getattr(mlist, 'crypto_processing') <> 1:
        return
    if not msgdata.get('decrypted'):
        return
    # Make a copy for each recipient, and re-queue the copies to the
incoming
    # queue.  Set the pipeline for the copies to just Decorate and
    # ToOutgoing.  The normal queue on the original copy should take
care of
    # everything else.
    newpipeline = ['Decorate', 'ToOutgoing']
    inq = get_switchboard(mm_cfg.INQUEUE_DIR)
    # Save the original To: line
    originalto = msg['To']
    # Create a separate message for each recipient
    savedmsg = msg
    for member in msgdata.get('recips', []):
        msg = savedmsg
        syslog('error', 'msg: %s' % msg)
        r_code = 1
        metadatacopy = msgdata.copy()
        metadatacopy['pipeline'] = newpipeline
        metadatacopy['recips'] = [member]
        metadatacopy['encrypted'] = 1
        del msg['To']
        name = mlist.getMemberName(member)
        if name:
            msg['To'] = '%s (%s)' % (member, name)
        else:
            msg['To'] = member
        # Walk the message tree and tree to encrypt text/plain parts.
        for part in msg.walk():
            if part.get_type('text/plain') == 'text/plain':
                # text/plain message part - encrypt it.
                value = part.get_payload()
                if not value:
                    pass
                else:
                    try:
                        syslog('error', 'value **2**: %s' % value)
                        (r_code,result) = IBE.encrypt_msg(value,
                                          
mlist.getMemberCPAddress(member))
                        syslog('error', 'result: %s' % result)
                        if r_code == 1:
                            part.set_payload("""Error occurred during
encryption
                                            of this message / message
part.\n\n
                                            Error msg:\n"""+result)
                        else:
                            part.set_payload(result)
                            del metadatacopy['decrypted']
                except Exception, e:
                    syslog('error', 'Error in encrypt_msg, IBE.py: %s' %
e)
            else:
                # Non text/plain msg part. Ignore.
                pass
        inq.enqueue(msg, metadatacopy, listname=mlist.internal_name())
    # Restore the original To: line
    del msg['To']
    msg['To'] = originalto
    # Don't let the normal ToOutgoing processing actually send the
original
    # copy.
    del msgdata['recips']
-----------------------------------------------------