Re: [gentoo-user] 2000 emails - printing, sorting by date

2016-08-18 Thread Stroller

> On 18 Aug 2016, at 08:16, Håkon Alstadheim  wrote:
> 
> Have you looked at app-misc/muttprint ? Never tried it, but looks to fit
> the bill. You will need various command-line tools that mutt-print will
> use to parse mails and generate graphics.

Ah! Many thanks. That's exactly the sort of thing I had in mind. I'll have a 
look at installing it now.

Stroller.




Re: [gentoo-user] 2000 emails - printing, sorting by date

2016-08-18 Thread Håkon Alstadheim
Den 18. aug. 2016 08:39, skrev Stroller:
>
>> On 17 Aug 2016, at 15:12, Daniel Quinn > > wrote:
>>
>> I’m a Python guy, so my answer to this would be "use Python" :-)
>>
>> [The ReportLab
>> library](https://www.reportlab.com/docs/reportlab-userguide.pdf) is
>> extremely powerful and can be used to generate a PDF for every email
>> or a pdf for all emails.  I've not used it myself, but I hear it's
>> very good.
>>
>> … 
>>
>> At that point you have a sorted list of email objects which you can
>> then use ReportLab to generate a PDF.
>
>
> That's a little more complicated than I hoped for.
>
Have you looked at app-misc/muttprint ? Never tried it, but looks to fit
the bill. You will need various command-line tools that mutt-print will
use to parse mails and generate graphics.




Re: [gentoo-user] 2000 emails - printing, sorting by date

2016-08-18 Thread Stroller

> On 17 Aug 2016, at 15:12, Daniel Quinn  wrote:
> 
> I’m a Python guy, so my answer to this would be "use Python" :-)
> 
> [The ReportLab 
> library](https://www.reportlab.com/docs/reportlab-userguide.pdf 
> ) is extremely 
> powerful and can be used to generate a PDF for every email or a pdf for all 
> emails.  I've not used it myself, but I hear it's very good.
> 
> … 
> 
> At that point you have a sorted list of email objects which you can then use 
> ReportLab to generate a PDF.


That's a little more complicated than I hoped for.

I've not used Python before. Although I'd not be opposed to learning it, it's 
not clear to me how I'd get ReportLab to generate a PDF from an email. 

I was not expecting to involve myself with decisions about fonts and heading 
sizes. I thought, perhaps optimistically, that there must be a command-line 
program to take a text email file and (discarding the unneeded headers) print 
it (to `lpr` or a postscript file) in formatting like the attached, just like 
my desktop email client does.

It surprises me to think that pretty-printing an email from the command-line is 
something that's not been done before, but my searches are not finding relevant 
results.

Stroller.





Re: [gentoo-user] 2000 emails - printing, sorting by date

2016-08-17 Thread Daniel Quinn

I’m a Python guy, so my answer to this would be "use Python" :-)

[The ReportLab 
library](https://www.reportlab.com/docs/reportlab-userguide.pdf) is 
extremely powerful and can be used to generate a PDF for every email or 
a pdf for all emails.  I've not used it myself, but I hear it's very good.


That’s the hard part really. Outside of that, you’d just use something 
like this:


```python
import os
from email import policy
from email.parser import BytesParser

maildir = "/path/to/maildir"
messages = []

for mail in os.listdir(maildir):
with open(os.path.join(maildir, mail)) as f:
raw = f.read()
message = BytesParser(policy=policy.default).parsebytes(f.read())
if "some...@somedomain.com" in raw:
messages.append(message)
```

Once you've created a collection of email objects, you can use the 
powers of the email module to easily parse out the bits you want. You 
can take a look at some code I wrote that does just that 
[here](https://github.com/UKTradeInvestment/barbara/blob/master/interactions/mail.py#L27). 
Once you've parsed the message, you can then sort your list based on the 
date.  Something like this:


```python
messages.sort(key=lambda _: _["Date"])
```

At that point you have a sorted list of email objects which you can then 
use ReportLab to generate a PDF.


Good luck :-)


[gentoo-user] 2000 emails - printing, sorting by date

2016-08-17 Thread Stroller
As a professional matter, I have about 2000 email messages that I want to share 
with someone.

I can find them all by grepping my Maildir for the email address (to and from) 
somen...@domain.com.

The person receiving them will probably not read every email, but this allows 
me to be totally open. I think that, glancing through, they'd quickly be able 
to verify what I've told them about myself and Some Name, and I think they'd 
find that helpful and reassuring.

The reader is not a geek, and I think a folder or zip file of 2000 separate 
email.txt files would be cumbersome to navigate.

I think the ideal thing to do is print the emails as a single PDF, ordered by 
date, so that the reader has a 2000-odd page PDF book they can browse. They can 
then note the page number of any specific email they wish to refer to, if they 
have any questions they need to ask.

The emails span about 10 years, 2000 - 2010 or so. Because these have been 
copied from one system to the other (perhaps carelessly), for many of them I am 
not certain that the file creation time will be correct.

I think that I can perhaps use net-mail/grepmail to find the earliest date in 
the header of each message, effectively constituting the "Sent" date. I'm not 
sure about this, though.

Using Bash I can probably renumber the messages based on this date, or change 
their file creation / modification time to that. 

I can probably then iterate through the messages, producing PDFs in numerical 
sequence (001.pdf, 002.pdf, or 2009-01-01.pdf, 2010-02-12.pdf), and then `for 
file in *.pdf ; do …` combine them into a single big PDF.

It's not clear to me what the best tools are for some of these steps, and I 
would be grateful if anyone has any thoughts, either on any individual steps, 
or on the whole process.

I use a Mac for my desktop, and so I wish to do this on the command-line of a 
headless Linux box.

What is the best way to pretty print each email, as a PDF, please?

I guess that I can use pdfunite from app-text/poppler to combine separate PDFs 
into one.

Thanks in advance for any suggestions,

Stroller.