Files
modoboa/extensions/amavis_quarantine/lib.py
T
tonio c01d6de7d8 fix: return receipts are now displayed correctly.
new: parameters module refactored. The API is more simple now, there is no need to provide a module name anymore, this last is automatically guessed. Also, a new 'label' field can be provide when declaring a new parameter. It will be used instead of the name.

new: email parsing refactored. My first attempt was really ugly. I did not really studied the various RFC describing how messages are formatted or what IMAP fetch queries can do. Now, I hope this new code will face better unknown types. At least, It will be simpler to update.
2010-09-17 09:23:35 +02:00

42 lines
1.2 KiB
Python

import socket
import re
import struct
import string
from modoboa.lib import parameters
class AMrelease(object):
def __init__(self):
mode = parameters.get_admin("AM_PDP_MODE")
if mode == "inet":
host = parameters.get_admin('AM_PDP_HOST')
port = parameters.get_admin('AM_PDP_PORT')
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.connect((host, int(port)))
else:
path = parameters.get_admin('AM_PDP_SOCKET')
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.sock.connect(path)
def decode(self, answer):
def repl(match):
return struct.pack("B", string.atoi(match.group(0)[1:], 16))
return re.sub(r"%([0-9a-fA-F]{2})", repl, answer)
def __del__(self):
self.sock.close()
def sendreq(self, mailid, secretid, recipient, *others):
self.sock.send("""request=release
mail_id=%s
secret_id=%s
quar_type=Q
recipient=%s
""" % (mailid, secretid, recipient))
answer = self.sock.recv(1024)
answer = self.decode(answer)
if re.search("250 [\d\.]+ Ok", answer):
return True
return False