mail-parser 3.14.0__tar.gz → 4.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mail_parser-4.0.0/LICENSE.txt +202 -0
- mail_parser-4.0.0/NOTICE.txt +13 -0
- mail_parser-4.0.0/PKG-INFO +330 -0
- {mail-parser-3.14.0 → mail_parser-4.0.0}/README.md +44 -27
- mail_parser-4.0.0/pyproject.toml +3 -0
- mail_parser-4.0.0/setup.cfg +74 -0
- mail_parser-4.0.0/setup.py +20 -0
- mail_parser-4.0.0/src/mail_parser.egg-info/PKG-INFO +330 -0
- mail_parser-4.0.0/src/mail_parser.egg-info/SOURCES.txt +22 -0
- mail_parser-4.0.0/src/mail_parser.egg-info/entry_points.txt +2 -0
- mail_parser-4.0.0/src/mail_parser.egg-info/requires.txt +15 -0
- {mail-parser-3.14.0 → mail_parser-4.0.0/src}/mailparser/const.py +6 -4
- {mail-parser-3.14.0 → mail_parser-4.0.0/src}/mailparser/mailparser.py +48 -10
- {mail-parser-3.14.0 → mail_parser-4.0.0/src}/mailparser/utils.py +27 -12
- {mail-parser-3.14.0 → mail_parser-4.0.0/src}/mailparser/version.py +1 -1
- mail_parser-4.0.0/tests/test_mail_parser.py +676 -0
- mail_parser-4.0.0/tests/test_main.py +99 -0
- mail-parser-3.14.0/PKG-INFO +0 -301
- mail-parser-3.14.0/mail_parser.egg-info/PKG-INFO +0 -301
- mail-parser-3.14.0/mail_parser.egg-info/SOURCES.txt +0 -18
- mail-parser-3.14.0/mail_parser.egg-info/entry_points.txt +0 -3
- mail-parser-3.14.0/mail_parser.egg-info/requires.txt +0 -5
- mail-parser-3.14.0/requirements.txt +0 -3
- mail-parser-3.14.0/setup.cfg +0 -7
- mail-parser-3.14.0/setup.py +0 -71
- {mail-parser-3.14.0 → mail_parser-4.0.0}/MANIFEST.in +0 -0
- {mail-parser-3.14.0 → mail_parser-4.0.0/src}/mail_parser.egg-info/dependency_links.txt +0 -0
- {mail-parser-3.14.0 → mail_parser-4.0.0/src}/mail_parser.egg-info/top_level.txt +0 -0
- {mail-parser-3.14.0 → mail_parser-4.0.0/src}/mailparser/__init__.py +0 -0
- {mail-parser-3.14.0 → mail_parser-4.0.0/src}/mailparser/__main__.py +0 -0
- {mail-parser-3.14.0 → mail_parser-4.0.0/src}/mailparser/exceptions.py +0 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2016 Fedele Mantuano (https://twitter.com/fedelemantuano)
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mail-parser
|
|
3
|
+
Version: 4.0.0
|
|
4
|
+
Summary: Improved wrapper for email standard library
|
|
5
|
+
Home-page: https://github.com/SpamScope/mail-parser
|
|
6
|
+
Author: Fedele Mantuano
|
|
7
|
+
Author-email: mantuano.fedele@gmail.com
|
|
8
|
+
Maintainer: Fedele Mantuano
|
|
9
|
+
Maintainer-email: mantuano.fedele@gmail.com
|
|
10
|
+
License: Apache License, Version 2.0
|
|
11
|
+
Keywords: email,mail,parser,spam,phishing,malware,forensic,analysis
|
|
12
|
+
Platform: OS Independent
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Natural Language :: English
|
|
16
|
+
Classifier: Programming Language :: Python
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Requires-Python: >=3.7
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE.txt
|
|
25
|
+
License-File: NOTICE.txt
|
|
26
|
+
Requires-Dist: ipaddress
|
|
27
|
+
Requires-Dist: six
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: build; extra == "dev"
|
|
30
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
31
|
+
Requires-Dist: wheel; extra == "dev"
|
|
32
|
+
Requires-Dist: twine; extra == "dev"
|
|
33
|
+
Provides-Extra: test
|
|
34
|
+
Requires-Dist: coverage; extra == "test"
|
|
35
|
+
Requires-Dist: pytest; extra == "test"
|
|
36
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
37
|
+
Requires-Dist: pytest-mock; extra == "test"
|
|
38
|
+
Requires-Dist: pytest-ordering; extra == "test"
|
|
39
|
+
|
|
40
|
+
[](https://badge.fury.io/py/mail-parser)
|
|
41
|
+
[](https://coveralls.io/github/SpamScope/mail-parser?branch=develop)
|
|
42
|
+
|
|
43
|
+

|
|
44
|
+
|
|
45
|
+
# mail-parser
|
|
46
|
+
|
|
47
|
+
mail-parser is not only a wrapper for [email](https://docs.python.org/2/library/email.message.html) Python Standard Library.
|
|
48
|
+
It give you an easy way to pass from raw mail to Python object that you can use in your code.
|
|
49
|
+
It's the key module of [SpamScope](https://github.com/SpamScope/spamscope).
|
|
50
|
+
|
|
51
|
+
mail-parser can parse Outlook email format (.msg). To use this feature, you need to install `libemail-outlook-message-perl` package. For Debian based systems:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
$ apt-get install libemail-outlook-message-perl
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For more details:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
$ apt-cache show libemail-outlook-message-perl
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
mail-parser supports Python 3.
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
# Apache 2 Open Source License
|
|
67
|
+
mail-parser can be downloaded, used, and modified free of charge. It is available under the Apache 2 license.
|
|
68
|
+
|
|
69
|
+
## Support the project
|
|
70
|
+
|
|
71
|
+
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VEPXYP745KJF2)
|
|
72
|
+
|
|
73
|
+
# mail-parser on Web
|
|
74
|
+
- [Splunk app](https://splunkbase.splunk.com/app/4129/)
|
|
75
|
+
- [FreeBSD port](https://www.freshports.org/mail/py-mail-parser/)
|
|
76
|
+
- [Arch User Repository](https://aur.archlinux.org/packages/mailparser/)
|
|
77
|
+
- [REMnux](https://docs.remnux.org/discover-the-tools/analyze+documents/email+messages#mail-parser)
|
|
78
|
+
|
|
79
|
+
# Description
|
|
80
|
+
|
|
81
|
+
mail-parser takes as input a raw email and generates a parsed object. The properties of this object are the same name of
|
|
82
|
+
[RFC headers](https://www.iana.org/assignments/message-headers/message-headers.xhtml):
|
|
83
|
+
|
|
84
|
+
- bcc
|
|
85
|
+
- cc
|
|
86
|
+
- date
|
|
87
|
+
- delivered_to
|
|
88
|
+
- from\_ (not `from` because is a keyword of Python)
|
|
89
|
+
- message_id
|
|
90
|
+
- received
|
|
91
|
+
- reply_to
|
|
92
|
+
- subject
|
|
93
|
+
- to
|
|
94
|
+
|
|
95
|
+
There are other properties to get:
|
|
96
|
+
- body
|
|
97
|
+
- body html
|
|
98
|
+
- body plain
|
|
99
|
+
- headers
|
|
100
|
+
- attachments
|
|
101
|
+
- sender IP address
|
|
102
|
+
- to domains
|
|
103
|
+
- timezone
|
|
104
|
+
|
|
105
|
+
The `attachments` property is a list of objects. Every object has the following keys:
|
|
106
|
+
- binary: it's true if the attachment is a binary
|
|
107
|
+
- charset
|
|
108
|
+
- content_transfer_encoding
|
|
109
|
+
- content-disposition
|
|
110
|
+
- content-id
|
|
111
|
+
- filename
|
|
112
|
+
- mail_content_type
|
|
113
|
+
- payload: attachment payload in base64
|
|
114
|
+
|
|
115
|
+
To get custom headers you should replace "-" with "\_".
|
|
116
|
+
Example for header `X-MSMail-Priority`:
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
$ mail.X_MSMail_Priority
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The `received` header is parsed and splitted in hop. The fields supported are:
|
|
123
|
+
- by
|
|
124
|
+
- date
|
|
125
|
+
- date_utc
|
|
126
|
+
- delay (between two hop)
|
|
127
|
+
- envelope_from
|
|
128
|
+
- envelope_sender
|
|
129
|
+
- for
|
|
130
|
+
- from
|
|
131
|
+
- hop
|
|
132
|
+
- with
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
mail-parser can detect defect in mail:
|
|
136
|
+
- [defects](https://docs.python.org/2/library/email.message.html#email.message.Message.defects): mail with some not compliance RFC part
|
|
137
|
+
|
|
138
|
+
All properties have a JSON and raw property that you can get with:
|
|
139
|
+
- name_json
|
|
140
|
+
- name_raw
|
|
141
|
+
|
|
142
|
+
Example:
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
$ mail.to (Python object)
|
|
146
|
+
$ mail.to_json (JSON)
|
|
147
|
+
$ mail.to_raw (raw header)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The command line tool use the JSON format.
|
|
151
|
+
|
|
152
|
+
## Defects
|
|
153
|
+
These defects can be used to evade the antispam filter. An example are the mails with a malformed boundary that can hide a not legitimate epilogue (often malware).
|
|
154
|
+
This library can take these epilogues.
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
# Authors
|
|
158
|
+
|
|
159
|
+
## Main Author
|
|
160
|
+
**Fedele Mantuano**: [LinkedIn](https://www.linkedin.com/in/fmantuano/)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
# Installation
|
|
164
|
+
|
|
165
|
+
Clone repository
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
git clone https://github.com/SpamScope/mail-parser.git
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
and install mail-parser with `setup.py`:
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
$ cd mail-parser
|
|
175
|
+
|
|
176
|
+
$ python setup.py install
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
or use `pip`:
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
$ pip install mail-parser
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
# Usage in a project
|
|
186
|
+
|
|
187
|
+
Import `mailparser` module:
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
import mailparser
|
|
191
|
+
|
|
192
|
+
mail = mailparser.parse_from_bytes(byte_mail)
|
|
193
|
+
mail = mailparser.parse_from_file(f)
|
|
194
|
+
mail = mailparser.parse_from_file_msg(outlook_mail)
|
|
195
|
+
mail = mailparser.parse_from_file_obj(fp)
|
|
196
|
+
mail = mailparser.parse_from_string(raw_mail)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Then you can get all parts
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
mail.attachments: list of all attachments
|
|
203
|
+
mail.body
|
|
204
|
+
mail.date: datetime object in UTC
|
|
205
|
+
mail.defects: defect RFC not compliance
|
|
206
|
+
mail.defects_categories: only defects categories
|
|
207
|
+
mail.delivered_to
|
|
208
|
+
mail.from_
|
|
209
|
+
mail.get_server_ipaddress(trust="my_server_mail_trust")
|
|
210
|
+
mail.headers
|
|
211
|
+
mail.mail: tokenized mail in a object
|
|
212
|
+
mail.message: email.message.Message object
|
|
213
|
+
mail.message_as_string: message as string
|
|
214
|
+
mail.message_id
|
|
215
|
+
mail.received
|
|
216
|
+
mail.subject
|
|
217
|
+
mail.text_plain: only text plain mail parts in a list
|
|
218
|
+
mail.text_html: only text html mail parts in a list
|
|
219
|
+
mail.text_not_managed: all not managed text (check the warning logs to find content subtype)
|
|
220
|
+
mail.to
|
|
221
|
+
mail.to_domains
|
|
222
|
+
mail.timezone: returns the timezone, offset from UTC
|
|
223
|
+
mail.mail_partial: returns only the mains parts of emails
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
It's possible to write the attachments on disk with the method:
|
|
227
|
+
|
|
228
|
+
```
|
|
229
|
+
mail.write_attachments(base_path)
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
# Usage from command-line
|
|
233
|
+
|
|
234
|
+
If you installed mailparser with `pip` or `setup.py` you can use it with command-line.
|
|
235
|
+
|
|
236
|
+
These are all swithes:
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
usage: mailparser [-h] (-f FILE | -s STRING | -k)
|
|
240
|
+
[-l {CRITICAL,ERROR,WARNING,INFO,DEBUG,NOTSET}] [-j] [-b]
|
|
241
|
+
[-a] [-r] [-t] [-dt] [-m] [-u] [-c] [-d] [-o]
|
|
242
|
+
[-i Trust mail server string] [-p] [-z] [-v]
|
|
243
|
+
|
|
244
|
+
Wrapper for email Python Standard Library
|
|
245
|
+
|
|
246
|
+
optional arguments:
|
|
247
|
+
-h, --help show this help message and exit
|
|
248
|
+
-f FILE, --file FILE Raw email file (default: None)
|
|
249
|
+
-s STRING, --string STRING
|
|
250
|
+
Raw email string (default: None)
|
|
251
|
+
-k, --stdin Enable parsing from stdin (default: False)
|
|
252
|
+
-l {CRITICAL,ERROR,WARNING,INFO,DEBUG,NOTSET}, --log-level {CRITICAL,ERROR,WARNING,INFO,DEBUG,NOTSET}
|
|
253
|
+
Set log level (default: WARNING)
|
|
254
|
+
-j, --json Show the JSON of parsed mail (default: False)
|
|
255
|
+
-b, --body Print the body of mail (default: False)
|
|
256
|
+
-a, --attachments Print the attachments of mail (default: False)
|
|
257
|
+
-r, --headers Print the headers of mail (default: False)
|
|
258
|
+
-t, --to Print the to of mail (default: False)
|
|
259
|
+
-dt, --delivered-to Print the delivered-to of mail (default: False)
|
|
260
|
+
-m, --from Print the from of mail (default: False)
|
|
261
|
+
-u, --subject Print the subject of mail (default: False)
|
|
262
|
+
-c, --receiveds Print all receiveds of mail (default: False)
|
|
263
|
+
-d, --defects Print the defects of mail (default: False)
|
|
264
|
+
-o, --outlook Analyze Outlook msg (default: False)
|
|
265
|
+
-i Trust mail server string, --senderip Trust mail server string
|
|
266
|
+
Extract a reliable sender IP address heuristically
|
|
267
|
+
(default: None)
|
|
268
|
+
-p, --mail-hash Print mail fingerprints without headers (default:
|
|
269
|
+
False)
|
|
270
|
+
-z, --attachments-hash
|
|
271
|
+
Print attachments with fingerprints (default: False)
|
|
272
|
+
-sa, --store-attachments
|
|
273
|
+
Store attachments on disk (default: False)
|
|
274
|
+
-ap ATTACHMENTS_PATH, --attachments-path ATTACHMENTS_PATH
|
|
275
|
+
Path where store attachments (default: /tmp)
|
|
276
|
+
-v, --version show program's version number and exit
|
|
277
|
+
|
|
278
|
+
It takes as input a raw mail and generates a parsed object.
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Example:
|
|
282
|
+
|
|
283
|
+
```shell
|
|
284
|
+
$ mailparser -f example_mail -j
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
This example will show you the tokenized mail in a JSON pretty format.
|
|
288
|
+
|
|
289
|
+
From [raw mail](https://gist.github.com/fedelemantuano/5dd702004c25a46b2bd60de21e67458e) to
|
|
290
|
+
[parsed mail](https://gist.github.com/fedelemantuano/e958aa2813c898db9d2d09469db8e6f6).
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
# Exceptions
|
|
294
|
+
|
|
295
|
+
Exceptions hierarchy of mail-parser:
|
|
296
|
+
|
|
297
|
+
```
|
|
298
|
+
MailParserError: Base MailParser Exception
|
|
299
|
+
|
|
|
300
|
+
\── MailParserOutlookError: Raised with Outlook integration errors
|
|
301
|
+
|
|
|
302
|
+
\── MailParserEnvironmentError: Raised when the environment is not correct
|
|
303
|
+
|
|
|
304
|
+
\── MailParserOSError: Raised when there is an OS error
|
|
305
|
+
|
|
|
306
|
+
\── MailParserReceivedParsingError: Raised when a received header cannot be parsed
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
# Development
|
|
310
|
+
The first step is to install the development environment:
|
|
311
|
+
|
|
312
|
+
```
|
|
313
|
+
$ python3.10 -m virtualenv venv
|
|
314
|
+
$ source venv/bin/activate
|
|
315
|
+
$ pip install -e ".[dev, test]"
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
The second step is to run the tests:
|
|
319
|
+
|
|
320
|
+
```
|
|
321
|
+
$ make test
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Then you can try to run the command line tool:
|
|
325
|
+
|
|
326
|
+
```
|
|
327
|
+
$ mail-parser -f tests/mails/mail_malformed_3 -j
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
If all is ok, you can start to develop.
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
[](https://badge.fury.io/py/mail-parser)
|
|
2
|
-
[](https://travis-ci.org/SpamScope/mail-parser)
|
|
3
2
|
[](https://coveralls.io/github/SpamScope/mail-parser?branch=develop)
|
|
4
|
-
[](https://bettercodehub.com/)
|
|
5
|
-
[](https://microbadger.com/images/fmantuano/spamscope-mail-parser "Get your own image badge on microbadger.com")
|
|
6
3
|
|
|
7
4
|

|
|
8
5
|
|
|
9
6
|
# mail-parser
|
|
10
7
|
|
|
11
|
-
## Overview
|
|
12
|
-
|
|
13
8
|
mail-parser is not only a wrapper for [email](https://docs.python.org/2/library/email.message.html) Python Standard Library.
|
|
14
9
|
It give you an easy way to pass from raw mail to Python object that you can use in your code.
|
|
15
10
|
It's the key module of [SpamScope](https://github.com/SpamScope/spamscope).
|
|
@@ -28,15 +23,23 @@ $ apt-cache show libemail-outlook-message-perl
|
|
|
28
23
|
|
|
29
24
|
mail-parser supports Python 3.
|
|
30
25
|
|
|
31
|
-
|
|
26
|
+
|
|
27
|
+
# Apache 2 Open Source License
|
|
28
|
+
mail-parser can be downloaded, used, and modified free of charge. It is available under the Apache 2 license.
|
|
29
|
+
|
|
30
|
+
## Support the project
|
|
31
|
+
|
|
32
|
+
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VEPXYP745KJF2)
|
|
33
|
+
|
|
34
|
+
# mail-parser on Web
|
|
32
35
|
- [Splunk app](https://splunkbase.splunk.com/app/4129/)
|
|
33
36
|
- [FreeBSD port](https://www.freshports.org/mail/py-mail-parser/)
|
|
34
37
|
- [Arch User Repository](https://aur.archlinux.org/packages/mailparser/)
|
|
38
|
+
- [REMnux](https://docs.remnux.org/discover-the-tools/analyze+documents/email+messages#mail-parser)
|
|
35
39
|
|
|
40
|
+
# Description
|
|
36
41
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
mail-parser takes as input a raw email and generates a parsed object. The properties of this object are the same name of
|
|
42
|
+
mail-parser takes as input a raw email and generates a parsed object. The properties of this object are the same name of
|
|
40
43
|
[RFC headers](https://www.iana.org/assignments/message-headers/message-headers.xhtml):
|
|
41
44
|
|
|
42
45
|
- bcc
|
|
@@ -107,27 +110,18 @@ $ mail.to_raw (raw header)
|
|
|
107
110
|
|
|
108
111
|
The command line tool use the JSON format.
|
|
109
112
|
|
|
110
|
-
|
|
113
|
+
## Defects
|
|
111
114
|
These defects can be used to evade the antispam filter. An example are the mails with a malformed boundary that can hide a not legitimate epilogue (often malware).
|
|
112
115
|
This library can take these epilogues.
|
|
113
116
|
|
|
114
117
|
|
|
115
|
-
|
|
116
|
-
mail-parser can be downloaded, used, and modified free of charge. It is available under the Apache 2 license.
|
|
117
|
-
|
|
118
|
-
If you want support the project:
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VEPXYP745KJF2)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
## Authors
|
|
118
|
+
# Authors
|
|
125
119
|
|
|
126
|
-
|
|
120
|
+
## Main Author
|
|
127
121
|
**Fedele Mantuano**: [LinkedIn](https://www.linkedin.com/in/fmantuano/)
|
|
128
122
|
|
|
129
123
|
|
|
130
|
-
|
|
124
|
+
# Installation
|
|
131
125
|
|
|
132
126
|
Clone repository
|
|
133
127
|
|
|
@@ -149,7 +143,7 @@ or use `pip`:
|
|
|
149
143
|
$ pip install mail-parser
|
|
150
144
|
```
|
|
151
145
|
|
|
152
|
-
|
|
146
|
+
# Usage in a project
|
|
153
147
|
|
|
154
148
|
Import `mailparser` module:
|
|
155
149
|
|
|
@@ -196,7 +190,7 @@ It's possible to write the attachments on disk with the method:
|
|
|
196
190
|
mail.write_attachments(base_path)
|
|
197
191
|
```
|
|
198
192
|
|
|
199
|
-
|
|
193
|
+
# Usage from command-line
|
|
200
194
|
|
|
201
195
|
If you installed mailparser with `pip` or `setup.py` you can use it with command-line.
|
|
202
196
|
|
|
@@ -216,7 +210,7 @@ optional arguments:
|
|
|
216
210
|
-s STRING, --string STRING
|
|
217
211
|
Raw email string (default: None)
|
|
218
212
|
-k, --stdin Enable parsing from stdin (default: False)
|
|
219
|
-
-l {CRITICAL,ERROR,WARNING,INFO,DEBUG,NOTSET}, --log-level {CRITICAL,ERROR,WARNING,INFO,DEBUG,NOTSET}
|
|
213
|
+
-l {CRITICAL,ERROR,WARNING,INFO,DEBUG,NOTSET}, --log-level {CRITICAL,ERROR,WARNING,INFO,DEBUG,NOTSET}
|
|
220
214
|
Set log level (default: WARNING)
|
|
221
215
|
-j, --json Show the JSON of parsed mail (default: False)
|
|
222
216
|
-b, --body Print the body of mail (default: False)
|
|
@@ -253,11 +247,11 @@ $ mailparser -f example_mail -j
|
|
|
253
247
|
|
|
254
248
|
This example will show you the tokenized mail in a JSON pretty format.
|
|
255
249
|
|
|
256
|
-
From [raw mail](https://gist.github.com/fedelemantuano/5dd702004c25a46b2bd60de21e67458e) to
|
|
250
|
+
From [raw mail](https://gist.github.com/fedelemantuano/5dd702004c25a46b2bd60de21e67458e) to
|
|
257
251
|
[parsed mail](https://gist.github.com/fedelemantuano/e958aa2813c898db9d2d09469db8e6f6).
|
|
258
252
|
|
|
259
253
|
|
|
260
|
-
|
|
254
|
+
# Exceptions
|
|
261
255
|
|
|
262
256
|
Exceptions hierarchy of mail-parser:
|
|
263
257
|
|
|
@@ -272,3 +266,26 @@ MailParserError: Base MailParser Exception
|
|
|
272
266
|
|
|
|
273
267
|
\── MailParserReceivedParsingError: Raised when a received header cannot be parsed
|
|
274
268
|
```
|
|
269
|
+
|
|
270
|
+
# Development
|
|
271
|
+
The first step is to install the development environment:
|
|
272
|
+
|
|
273
|
+
```
|
|
274
|
+
$ python3.10 -m virtualenv venv
|
|
275
|
+
$ source venv/bin/activate
|
|
276
|
+
$ pip install -e ".[dev, test]"
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
The second step is to run the tests:
|
|
280
|
+
|
|
281
|
+
```
|
|
282
|
+
$ make test
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
Then you can try to run the command line tool:
|
|
286
|
+
|
|
287
|
+
```
|
|
288
|
+
$ mail-parser -f tests/mails/mail_malformed_3 -j
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
If all is ok, you can start to develop.
|