1 |
I’m a Python guy, so my answer to this would be "use Python" :-) |
2 |
|
3 |
[The ReportLab |
4 |
library](https://www.reportlab.com/docs/reportlab-userguide.pdf) is |
5 |
extremely powerful and can be used to generate a PDF for every email or |
6 |
a pdf for all emails. I've not used it myself, but I hear it's very good. |
7 |
|
8 |
That’s the hard part really. Outside of that, you’d just use something |
9 |
like this: |
10 |
|
11 |
```python |
12 |
import os |
13 |
from email import policy |
14 |
from email.parser import BytesParser |
15 |
|
16 |
maildir = "/path/to/maildir" |
17 |
messages = [] |
18 |
|
19 |
for mail in os.listdir(maildir): |
20 |
with open(os.path.join(maildir, mail)) as f: |
21 |
raw = f.read() |
22 |
message = BytesParser(policy=policy.default).parsebytes(f.read()) |
23 |
if "someone@××××××××××.com" in raw: |
24 |
messages.append(message) |
25 |
``` |
26 |
|
27 |
Once you've created a collection of email objects, you can use the |
28 |
powers of the email module to easily parse out the bits you want. You |
29 |
can take a look at some code I wrote that does just that |
30 |
[here](https://github.com/UKTradeInvestment/barbara/blob/master/interactions/mail.py#L27). |
31 |
Once you've parsed the message, you can then sort your list based on the |
32 |
date. Something like this: |
33 |
|
34 |
```python |
35 |
messages.sort(key=lambda _: _["Date"]) |
36 |
``` |
37 |
|
38 |
At that point you have a sorted list of email objects which you can then |
39 |
use ReportLab to generate a PDF. |
40 |
|
41 |
Good luck :-) |