Example #1
0
    def start(self, one_shot=False):
        """
        Start simply loops indefinitely sleeping and pulling messages
        off for processing when they are available.

        If you give one_shot=True it will stop once it has exhausted the queue
        """

        logging.info("Queue receiver started on queue dir %s", self.queue_dir)
        salmonscheduler.schedule()
        inq = queue.Queue(self.queue_dir)

        while True:
            keys = inq.keys()
            for key in keys:
                msg = inq.get(key)
                if msg:
                    logging.info("Pulled message with key: %r off", key)
                    salmonmailparser.process_email(key, msg)
                    logging.info("Removed %r key from queue.\n\n", key)
                inq.remove(key)
            if one_shot:
                return
            else:
                time.sleep(self.sleep)
Example #2
0
 def test_eml_without_attachment(self):
     mail_request = MailRequest(
         self.eml_file1, None, None, self.eml_content(self.eml_file1)
     )
     mail_fields = process_email(self.eml_file1, mail_request)
     assert isinstance(mail_fields, dict)
     assert len(mail_fields["attachmentFileName"]) == 0
Example #3
0
 def test_eml_with_inline(self):
     mail_request = MailRequest(
         self.eml_file4, None, None, self.eml_content(self.eml_file4)
     )
     mail_fields = process_email(self.eml_file4, mail_request)
     assert len(mail_fields["attachmentFileName"]) == 1
     assert mail_fields["attachmentFileName"][0] == None
Example #4
0
 def test_bad_reply_to(self):
     mail_request = MailRequest(
         self.eml_file2, None, None, self.eml_content(self.eml_file2)
     )
     mail_fields = process_email(self.eml_file2, mail_request)
     assert isinstance(mail_fields, dict)
     assert mail_fields["reply-to"] == "-"
Example #5
0
 def test_eml_with_attachment(self):
     mail_request = MailRequest(
         self.eml_file2, None, None, self.eml_content(self.eml_file2)
     )
     mail_fields = process_email(self.eml_file2, mail_request)
     assert isinstance(mail_fields, dict)
     assert len(mail_fields["attachmentFileName"]) == 1
     assert mail_fields["attachmentFileName"][0] == "my_attach.doc"
Example #6
0
 def test_link_in_eml(self):
     mail_request = MailRequest(
         self.eml_file3, None, None, self.eml_content(self.eml_file3)
     )
     mail_fields = process_email(self.eml_file3, mail_request)
     assert isinstance(mail_fields, dict)
     assert len(mail_fields["links"]) > 0
     assert mail_fields["links"][0] == "www.test.cz"
Example #7
0
 def test_rating_100_1(self, f_password):
     """Test email with the password in body_plain"""
     self.password4 = "changeme"
     self.username4 = "changeme"
     self.settings4 = Settings(username=self.username4,
                               password=self.password4)
     push_into_db(self.settings4)
     mail_request = MailRequest(self.eml_file1, None, None,
                                self.eml_content(self.eml_file1))
     mail_fields = process_email(self.eml_file1, mail_request)
     rating = conclude(mail_fields, self.eml_file1, mail_request)
     assert rating == 100
Example #8
0
 def test_mail_fields(self):
     mail_request = MailRequest(
         self.eml_file1, None, None, self.eml_content(self.eml_file1)
     )
     mail_fields = process_email(self.eml_file1, mail_request)
     assert isinstance(mail_fields, dict)
     assert mail_fields["to"][0][0] == "*****@*****.**"
     assert mail_fields["reply-to"] == "*****@*****.**"
     assert mail_fields["from"] == "*****@*****.**"
     assert mail_fields["from_name"] == "Test Test"
     assert mail_fields["subject"] == "Hello"
     assert mail_fields["text"] == "test"
Example #9
0
def run(files, directory, mtimes):
    mail_fields = None
    for file_name in files:
        mail_request = MailRequest(
            file_name, None, None, eml_content(file_name, directory)
        )
        mail_fields = process_email(file_name, mail_request)
        if mail_fields:
            mtime = mtimes[file_name]
            mail_fields["date"] = mtime
            rating = conclude(mail_fields, file_name, mail_request)
            if rating >= 70 and RELAYED < 13:
                RELAYED += 1