mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
@@ -162,7 +162,7 @@ class Quarantine(models.Model):
|
||||
partition_tag = models.IntegerField(null=True, blank=True)
|
||||
mail = models.ForeignKey(Msgs, primary_key=True)
|
||||
chunk_ind = models.IntegerField()
|
||||
mail_text = models.TextField()
|
||||
mail_text = models.BinaryField()
|
||||
|
||||
class Meta:
|
||||
db_table = u'quarantine'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
SQL connector module.
|
||||
"""
|
||||
|
||||
import datetime
|
||||
|
||||
from django.db.models import Q
|
||||
@@ -209,9 +210,14 @@ class SQLconnector(object):
|
||||
return Msgrcpt.objects.filter(rq).count()
|
||||
|
||||
def get_mail_content(self, mailid):
|
||||
"""Retrieve the content of a message.
|
||||
"""
|
||||
return Quarantine.objects.filter(mail=mailid)
|
||||
"""Retrieve the content of a message."""
|
||||
content = "".join([
|
||||
str(qmail.mail_text)
|
||||
for qmail in Quarantine.objects.filter(mail=mailid)
|
||||
])
|
||||
if isinstance(content, unicode):
|
||||
content = content.encode("utf-8")
|
||||
return content
|
||||
|
||||
|
||||
class PgSQLconnector(SQLconnector):
|
||||
@@ -229,9 +235,7 @@ class PgSQLconnector(SQLconnector):
|
||||
"""
|
||||
|
||||
def _apply_msgrcpt_filters(self, flt):
|
||||
"""Return filters based on user's role.
|
||||
|
||||
"""
|
||||
"""Return filters based on user's role. """
|
||||
self._where = []
|
||||
if self.user.group == 'SimpleUsers':
|
||||
rcpts = [self.user.email]
|
||||
@@ -248,10 +252,7 @@ class PgSQLconnector(SQLconnector):
|
||||
return flt
|
||||
|
||||
def _apply_extra_search_filter(self, crit, pattern):
|
||||
"""Apply search filters using additional criterias.
|
||||
|
||||
|
||||
"""
|
||||
"""Apply search filters using additional criterias."""
|
||||
if crit == "to":
|
||||
self._where.append(
|
||||
"convert_from(maddr.email, 'UTF8') LIKE '%%{0}%%'".format(
|
||||
@@ -300,12 +301,6 @@ class PgSQLconnector(SQLconnector):
|
||||
).count()
|
||||
return Msgrcpt.objects.filter(rq).count()
|
||||
|
||||
def get_mail_content(self, mailid):
|
||||
"""Retrieve the content of a message."""
|
||||
return Quarantine.objects.filter(mail=mailid).extra(
|
||||
select={'mail_text': "convert_from(mail_text, 'UTF8')"}
|
||||
)
|
||||
|
||||
|
||||
def get_connector(**kwargs):
|
||||
"""Return the appropriate *connector* class.
|
||||
|
||||
@@ -40,10 +40,7 @@ class SQLemail(Email):
|
||||
import email
|
||||
|
||||
if self._msg is None:
|
||||
qmails = get_connector().get_mail_content(self.mailid)
|
||||
mail_text = "".join([qm.mail_text for qm in qmails])
|
||||
if type(mail_text) is unicode:
|
||||
mail_text = mail_text.encode("utf-8")
|
||||
mail_text = get_connector().get_mail_content(self.mailid)
|
||||
self._msg = email.message_from_string(mail_text)
|
||||
self._parse(self._msg)
|
||||
return self._msg
|
||||
|
||||
@@ -176,11 +176,7 @@ def viewmail(request, mail_id):
|
||||
@login_required
|
||||
def viewheaders(request, mail_id):
|
||||
"""Display message headers."""
|
||||
content = ""
|
||||
for qm in get_connector().get_mail_content(mail_id):
|
||||
content += qm.mail_text
|
||||
if type(content) is unicode:
|
||||
content = content.encode("utf-8")
|
||||
content = get_connector().get_mail_content(mail_id)
|
||||
msg = email.message_from_string(content)
|
||||
headers = []
|
||||
for name, value in msg.items():
|
||||
@@ -348,9 +344,7 @@ def mark_messages(request, selection, mtype, recipient_db=None):
|
||||
saclient = SpamassassinClient(request.user, recipient_db)
|
||||
for item in selection:
|
||||
rcpt, mail_id = item.split()
|
||||
content = "".join(
|
||||
[msg.mail_text for msg in connector.get_mail_content(mail_id)]
|
||||
)
|
||||
content = connector.get_mail_content(mail_id)
|
||||
result = saclient.learn_spam(rcpt, content) if mtype == "spam" \
|
||||
else saclient.learn_ham(rcpt, content)
|
||||
if not result:
|
||||
|
||||
Reference in New Issue
Block a user