def test_to_addresses(self): mailfile = os.path.join(os.path.dirname(__file__), 'samples/mail_with_attachment.eml') r = Resource(mailfile) rs = ResourceSet([r]) # we shouldn't be able to extract a to address because we only have a zip file assert rs.to_addresses == ['*****@*****.**'] assert rs.to_localpart == 'alice' assert rs.to_domain == 'example.com' # this mail has the To header set to # To: Alice <*****@*****.**> mailfile = os.path.join(os.path.dirname(__file__), 'samples/mail_full_email_in_to.eml') r = Resource(mailfile) rs = ResourceSet([r]) # we shouldn't be able to extract a to address because we only have a zip file assert rs.to_addresses == ['*****@*****.**'] assert rs.to_localpart == 'alice' assert rs.to_domain == 'example.com' # this mail has the To header set to # To: To: undisclosed-recipients:; mailfile = os.path.join(os.path.dirname(__file__), 'samples/mail_no_email_in_to.eml') r = Resource(mailfile) rs = ResourceSet([r]) # we shouldn't be able to extract a to address because we only have a zip file assert rs.to_addresses == [] assert rs.to_localpart is None assert rs.to_domain is None
def test_mail_file(self): # a mail with an single text/plain part path = self._resource('test2_rfc822.eml') r = Resource(path) assert r.path == path assert r.can_unpack assert r.md5 == "0a7e2dfa25a3db3ab1a4773a17d1527e" assert r.sha1 == "b0c42741af78f8311abeff543be8f3c62247168a" assert r.sha256 == "8179aa7716740f099a43d6c0aa8b77622dbbd7050bc56ce21cda2109444cf3d6" assert r.mime_type == 'message/rfc822' resources = list(r.unpack()) assert len(resources) == 0
def test_no_to_addresses(self): zipfile = os.path.join(os.path.dirname(__file__), 'samples/textfile.zip') r = Resource(zipfile) rs = ResourceSet([r]) # we shouldn't be able to extract a to address because we only have a zip file assert rs.to_addresses == [] assert rs.to_localpart is None assert rs.to_domain is None
def test_empty_file(self): # literally, an empty mail path = self._resource('test1_empty.eml') r = Resource(path) assert r.path == path assert r.can_unpack is False assert r.md5 == "d41d8cd98f00b204e9800998ecf8427e" assert r.sha1 == "da39a3ee5e6b4b0d3255bfef95601890afd80709" assert r.sha256 == "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" assert r.mime_type == 'application/x-empty'
def test_iter(self): zipfile = os.path.join(os.path.dirname(__file__), 'samples/textfile.zip') r = Resource(zipfile) rs = ResourceSet([r]) assert len(rs) == 1 l = list(rs) assert len(l) == 1 assert isinstance(l[0], Resource) assert l[0] == r
def test_mail_with_single_payload(self): path = self._resource('test3_rfc822_with_single_payload.eml') r = Resource(path) assert r.path == path assert r.can_unpack assert r.md5 == "6f25abac24792456c3741ef64cdd7a4d" assert r.sha1 == "605f7ace5dcac01ebfb154c5b559cbd07662fad0" assert r.sha256 == "c958f80e05844e7504d4ff705ffaebefa49bbfd8ce882e9a7267b9f176d8e96d" assert r.mime_type == 'message/rfc822' resources = list(r.unpack()) assert len(resources) == 1 zip_attachment = resources[0] assert not zip_attachment.can_unpack assert zip_attachment.md5 == "e77d94e09fbcf6641c1f848d98963298" assert zip_attachment.sha1 == "acbfc25a642cb7fa574f38a361932d1c2fdc1a9e" assert zip_attachment.sha256 == "93440551540584e48d911586606c319744c8e671c20ee6b12cca4b922127a127" assert zip_attachment.mime_type == "application/zip" for x in resources: if not x.path == r.path: os.remove(x.path)
def test_unpack_mail(self): # multi-part email with a zip file attachment path = self._resource('mail_with_attachment.eml') r = Resource(path) assert r.mime_type == "message/rfc822" assert r.can_unpack assert r.md5 == "b9a864ccc860e4f30193c7b75de116cf" assert r.sha1 == "5e1b7f725dad50407871b02a4a4558da0c734317" assert r.sha256 == "0eb18a25bcc56ca4b503b1406d9af35928e754aebbe55452299c9cf2cd8245f1" resources = list(r.unpack()) assert len(resources) == 1 zip_attachment = resources[0] assert not zip_attachment.can_unpack assert zip_attachment.md5 == "e77d94e09fbcf6641c1f848d98963298" assert zip_attachment.sha1 == "acbfc25a642cb7fa574f38a361932d1c2fdc1a9e" assert zip_attachment.sha256 == "93440551540584e48d911586606c319744c8e671c20ee6b12cca4b922127a127" assert zip_attachment.mime_type == "application/zip" for x in resources: if not x.path == r.path: os.remove(x.path)
def do_report(self, filename_argument): filename = os.path.abspath(filename_argument) if not (os.path.exists(filename) and os.path.isfile(filename) and os.access(filename, os.R_OK)): logger.error("File does not exist or is inaccessible: '%s'", filename) self.send_response( "ERROR: File does not exist or is inaccessible: '%s'" % filename) return avt = AmavisVT(self.config) result = avt.report_to_vt( Resource(filename, cleanup=False, no_unpack=True)) self.send_response(str(result) if result else "No response")
def test_property_size(self): r = Resource('/etc') assert r.size == os.path.getsize(r.path)