Exemple #1
0
    def fetch(self, start, stop=None, mbox=None, **kwargs):
        """Retrieve information about messages from the server

        Issue a FETCH command to retrieve information about one or
        more messages (such as headers) from the server.

        :param start: index of the first message
        :param stop: index of the last message (optionnal)
        :param mbox: the mailbox that contains the messages
        """
        self.select_mailbox(mbox, False)
        if start and stop:
            submessages = self.messages[start - 1:stop]
            range = ",".join(submessages)
        else:
            submessages = [start]
            range = start
        query = '(FLAGS BODYSTRUCTURE BODY.PEEK[HEADER.FIELDS (DATE FROM TO CC SUBJECT)])'
        data = self._cmd("FETCH", range, query)
        result = []
        for uid in submessages:
            msg = email.message_from_string(data[int(
                uid)]['BODY[HEADER.FIELDS (DATE FROM TO CC SUBJECT)]'])
            msg['imapid'] = uid
            if not r'\Seen' in data[int(uid)]['FLAGS']:
                msg['style'] = 'unseen'
            if r'\Answered' in data[int(uid)]['FLAGS']:
                msg['img_flags'] = [static_url('pics/answered.png')]
            if r'$Forwarded' in data[int(uid)]['FLAGS']:
                if msg.has_key('img_flags'):
                    msg['img_flags'] += [static_url('pics/forwarded.png')]
                else:
                    msg['img_flags'] = [static_url('pics/forwarded.png')]
            bs = BodyStructure(data[int(uid)]['BODYSTRUCTURE'])
            if bs.has_attachments():
                msg['img_withatts'] = static_url('pics/attachment.png')
            result += [msg]
        return result
Exemple #2
0
    def fetch(self, start, stop=None, mbox=None, **kwargs):
        """Retrieve information about messages from the server

        Issue a FETCH command to retrieve information about one or
        more messages (such as headers) from the server.

        :param start: index of the first message
        :param stop: index of the last message (optionnal)
        :param mbox: the mailbox that contains the messages
        """
        self.select_mailbox(mbox, False)
        if start and stop:
            submessages = self.messages[start - 1:stop]
            range = ",".join(submessages)
        else:
            submessages = [start]
            range = start
        query = '(FLAGS BODYSTRUCTURE BODY.PEEK[HEADER.FIELDS (DATE FROM TO CC SUBJECT)])'
        data = self._cmd("FETCH", range, query)
        result = []
        for uid in submessages:
            msg = email.message_from_string(data[int(uid)]['BODY[HEADER.FIELDS (DATE FROM TO CC SUBJECT)]'])
            msg['imapid'] = uid
            if not r'\Seen' in data[int(uid)]['FLAGS']:
                msg['style'] = 'unseen'
            if r'\Answered' in data[int(uid)]['FLAGS']:
                msg['img_flags'] = [static_url('pics/answered.png')]
            if r'$Forwarded' in data[int(uid)]['FLAGS']:
                if msg.has_key('img_flags'):
                    msg['img_flags'] += [static_url('pics/forwarded.png')]
                else:
                    msg['img_flags'] = [static_url('pics/forwarded.png')]
            bs = BodyStructure(data[int(uid)]['BODYSTRUCTURE'])
            if bs.has_attachments():
                msg['img_withatts'] = static_url('pics/attachment.png')
            result += [msg]
        return result
Exemple #3
0
 def fetch(self, start=None, stop=None, **kwargs):
     messages = self.messages[start - 1:stop]
     emails = []
     for qm in messages:
         for rcpt in qm.mail.msgrcpt_set.all():
             m = {"from": qm.mail.from_addr,
                  "to": rcpt.rid.email,
                  "subject": qm.mail.subject,
                  "mailid": qm.mail_id,
                  "date": qm.mail.time_num,
                  "type": rcpt.content}
             if rcpt.rs == '':
                 m["class"] = "unseen"
             elif rcpt.rs == 'R':
                 m["img_rstatus"] = static_url("pics/release.png")
             elif rcpt.rs == 'p':
                 m["class"] = "pending"
             emails.append(m)
     return emails
Exemple #4
0
 def fetch(self, start=None, stop=None, **kwargs):
     emails = []
     for qm in self.messages[start - 1:stop]:
         m = {"from": qm["mail__from_addr"],
              "to": qm["mail__msgrcpt__rid__email"],
              "subject": qm["mail__subject"],
              "mailid": qm["mail__mail_id"],
              "date": qm["mail__time_num"],
              "type": qm["mail__msgrcpt__content"],
              "score": qm["mail__msgrcpt__bspam_level"]}
         rs = qm["mail__msgrcpt__rs"]
         if rs == '':
             m["class"] = "unseen"
         elif rs == 'R':
             m["img_rstatus"] = static_url("pics/release.png")
         elif rs == 'p':
             m["class"] = "pending"
         emails.append(m)
     return emails
Exemple #5
0
def menu(target, user):
    if target != "top_menu_middle":
        return []
    if not user.mailbox_set.count():
        return []
    return [
        {"name": "demo",
         "label": _("Test messages"),
         "img": static_url("pics/demo.png"),
         "class": "topdropdown",
         "menu": [
             {"name": "sendvirus",
              "label":  _("Send virus"),
              "url": reverse("modoboa.demo.views.send_virus")},
             {"name": "sendspam",
              "label":  _("Send spam"),
              "url": reverse("modoboa.demo.views.send_spam")}
         ]
         }
    ]
Exemple #6
0
def menu(target, user):
    if target != "top_menu_middle":
        return []
    if not user.mailbox_set.count():
        return []
    return [
        {"name": "demo",
         "label": _("Test messages"),
         "img": static_url("pics/demo.png"),
         "class": "topdropdown",
         "menu": [
             {"name": "sendvirus",
              "label":  _("Send virus"),
              "url": reverse("demo:virus_send")},
             {"name": "sendspam",
              "label":  _("Send spam"),
              "url": reverse("demo:spam_send")}
         ]
         }
    ]
Exemple #7
0
 def fetch(self, start=None, stop=None, **kwargs):
     emails = []
     for qm in self.messages[start - 1:stop]:
         m = {"from": qm["mail__from_addr"],
              "to": qm["mail__msgrcpt__rid__email"],
              "subject": qm["mail__subject"],
              "mailid": qm["mail__mail_id"],
              "date": qm["mail__time_num"],
              "type": qm["mail__msgrcpt__content"],
              "score": qm["mail__msgrcpt__bspam_level"]}
         rs = qm["mail__msgrcpt__rs"]
         if rs == 'D':
             continue
         elif rs == '':
             m["class"] = "unseen"
         elif rs == 'R':
             m["img_rstatus"] = static_url("pics/release.png")
         elif rs == 'p':
             m["class"] = "pending"
         emails.append(m)
     return emails
Exemple #8
0
 def fetch(self, start=None, stop=None, **kwargs):
     messages = self.messages[start - 1:stop]
     emails = []
     for qm in messages:
         for rcpt in qm.mail.msgrcpt_set.all():
             m = {
                 "from": qm.mail.from_addr,
                 "to": rcpt.rid.email,
                 "subject": qm.mail.subject,
                 "mailid": qm.mail_id,
                 "date": qm.mail.time_num,
                 "type": rcpt.content
             }
             if rcpt.rs == '':
                 m["class"] = "unseen"
             elif rcpt.rs == 'R':
                 m["img_rstatus"] = static_url("pics/release.png")
             elif rcpt.rs == 'p':
                 m["class"] = "pending"
             emails.append(m)
     return emails
Exemple #9
0
    def fetch(self, start=None, stop=None, **kwargs):
        """Fetch a range of messages from the internal cache.

        """
        emails = []
        for qm in self.messages[start - 1:stop]:
            m = {"from": qm["mail__from_addr"],
                 "to": qm["rid__email"],
                 "subject": qm["mail__subject"],
                 "mailid": qm["mail__mail_id"],
                 "date": qm["mail__time_num"],
                 "type": qm["content"],
                 "score": qm["bspam_level"]}
            rs = qm["rs"]
            if rs == 'D':
                continue
            elif rs in ['', ' ']:
                m["class"] = "unseen"
            elif rs == 'R':
                m["img_rstatus"] = static_url("pics/release.png")
            elif rs == 'p':
                m["class"] = "pending"
            emails.append(m)
        return emails
Exemple #10
0
def menu(target, user):
    if target != "top_menu_middle":
        return []
    if not user.has_mailbox:
        return []
    return [{
        "name":
        "demo",
        "label":
        _("Test messages"),
        "img":
        static_url("pics/demo.png"),
        "class":
        "topdropdown",
        "menu": [{
            "name": "sendvirus",
            "label": _("Send virus"),
            "url": reverse("modoboa.demo.views.send_virus")
        }, {
            "name": "sendspam",
            "label": _("Send spam"),
            "url": reverse("modoboa.demo.views.send_spam")
        }]
    }]