Example #1
0
 def _get_authors(self, msg):
     self.author_addresses = msg.get_addr_header("From")
     for header in self.author_addresses:
         match_domain = Regex("@([^@]+?)[ \t]*$").search(header)
         if match_domain:
             domain = match_domain.group(1)
             self.author_domains.append(domain.encode())
Example #2
0
 def check_ratware_envelope_from(self, msg, target=None):
     """Check if envelope-from address is ratware or not."""
     to_header = msg.msg.get("To")
     envelope_from = msg.sender_address
     if not to_header or not envelope_from:
         return False
     if Regex(r"^SRS\d=").search(envelope_from):
         return False
     regex = Regex(r"^([^@]+)@(.+)$").search(to_header)
     if regex:
         user = regex.group(1)
         dom = regex.group(2)
         if not self.is_domain_valid(dom):
             return False
         if Regex(r"\b" + dom + "." + user + "@").search(envelope_from):
             return True
     return False
Example #3
0
 def check_ratware_name_id(self, msg, target=None):
     """Check if message-id is ratware or not."""
     message_id = msg.msg.get("Message-Id")
     from_header = msg.msg.get("From")
     if not message_id and not from_header:
         return False
     regex = Regex(r"<[A-Z]{28}\.([^>]+?)>").search(message_id)
     if regex:
         if Regex(r"\"[^\"]+\"\s*<" + regex.group(1) + ">").search(
                 from_header):
             return True
     return False
Example #4
0
    def check_for_unique_subject_id(self, msg, target=None):
        """Check if in subject appears an unique id"""
        subject = "".join(msg.get_decoded_header("Subject"))
        id = None
        unique_id_re_list = [
            r"[-_\.\s]{7,}([-a-z0-9]{4,})$",
            r"\s{10,}(?:\S\s)?(\S+)$",
            r"\s{3,}[-:\#\(\[]+([-a-z0-9]{4,})[\]\)]+$",
            r"\s{3,}[-:\#]([a-z0-9]{5,})$",
            r"[\s._]{3,}([^0\s._]\d{3,})$",
            r"[\s._]{3,}\[(\S+)\]$",

            # (7217vPhZ0-478TLdy5829qicU9-0@26) and similar
            r"\(([-\w]{7,}\@\d+)\)$",
            r"\b(\d{7,})\s*$",

            # stuff at end of line after "!" or "?" is usually an id
            r"[!\?]\s*(\d{4,}|\w+(-\w+)+)\s*$",

            # 9095IPZK7-095wsvp8715rJgY8-286-28 and similar
            # excluding 'Re:', etc and the first word
            r"(?:\w{2,3}:\s)?\w+\s+(\w{7,}-\w{7,}(-\w+)*)\s*$",

            # #30D7 and similar
            r"\s#\s*([a-f0-9]{4,})\s*$"
        ]
        for rgx in unique_id_re_list:
            match = Regex(rgx, re.I).search(subject)
            if match:
                id = match.group()
                break
        if not id:
            return False
        comercial_re = Regex(r"(?:item|invoice|order|number|confirmation)"
                             r".{1,6}%s\s*$" % id, re.X | re.I)
        if Regex(r"\d{5,}").search(id) and comercial_re.search(subject):
            return False
        return True
Example #5
0
    def send_mail_method(self, sender, receiver, message):
        """
        Send mail using smtplib module.
        :param sender:
        :param receiver:
        :param message:
        """
        try:
            regex = Regex(".*@.*").search(receiver)
            domain = regex.group().split('@')[1]
            # return value like '0 mail.domain.com.'
            mx_domain = self.ctxt.dns.query(domain, 'MX')[0].to_text()
            mx_domain = mx_domain.split()[1][:-1]

            smtp_obj = smtplib.SMTP()
            smtp_obj.connect(mx_domain, 587)
            smtp_obj.helo(mx_domain.split('.')[1])
            smtp_obj.sendmail(sender, receiver, message)
            smtp_obj.quit()
        except BaseException:
            self.ctxt.log.warning("SpamCop report failed.")
            return False
        return True