How do I do this in Python 3 (string.join())?
Chris Green
cl at isbd.net
Fri Aug 28 03:50:10 EDT 2020
Cameron Simpson <cs at cskk.id.au> wrote:
[snip]
>
> >The POP3 processing is solely to collect E-Mail that ends up in the
> >'catchall' mailbox on my hosting provider. It empties the POP3
> >catchall mailbox, checks for anything that *might* be for me or other
> >family members then just deletes the rest.
>
> Very strong email policy, that one. Personally I fear data loss, and
> process everything; anything which doesn't match a rule lands in my
> "UNKNOWN" mail folder for manual consideration when I'm bored. It is
> largely spam, but sometimes has a message wanting a new filing rule.
>
It's not *that* strong, the catchall is for *anything* that is
addressed to either of the two domains hosted there. I.e. mail for
xhghjhwd at isbd.net will arrive in the catchall mailbox. So I just
search the To: address for anything that might be a typo for one of
our names or anything else that might be of interest. I have an
associated configuration file that specifies the patterns to look for
so I can change things on the fly as it were.
One of the scripts that I'm having trouble converting to Python 3 is
the one that does this catchall management.
> >> >E.g. in this case the only (well the only ready made) way to get a
> >> >POP3 message is using poplib and this just gives you a list of lines
> >> >made up of "bytes as text" :-
> >> >
> >> > popmsg = pop3.retr(i+1)
> >>
> >> Ok, so you have bytes? You need to know.
> >>
> >The documentation says (and it's exactly the same for Python 2 and
> >Python 3):-
> >
> > POP3.retr(which)
> > Retrieve whole message number which, and set its seen flag. Result
> > is in form (response, ['line', ...], octets).
> >
> >Which isn't amazingly explicit unless 'line' implies a string.
>
> Aye. But "print(repr(a_pop_line))" will tell you. Almost certainly a
> string-of-bytes, so I would expect bytes. The docs are probably
> unchanged during the Python2->3 move.
>
Yes, I added some print statments to my catchall script to find out
and, yes, the returned value is a list of 'byte strings'. It's a pity
there isn't a less ambiguous name for 'string-of-bytes'! :-)
> >> >I join the lines to feed them into mailbox.mbox() to create a mbox I
> >> >can analyse and also a message which can be sent using SMTP.
>
> Ah. I like Maildirs for analysis; every message has its own file, which
> makes adding and removing messages easy, and avoids contention with
> other things using the Maildir.
>
> My mailfiler can process Maildirs (scan, add, remove) and add to
> Maildirs and mboxes.
>
I've switched to maildir several times in the past and have always
switched back because they have so many 'standards'. I use mutt as my
MUA and that does handle maildir as well as anything but still doesn't
do it for me. :-)
--
Chris Green
ยท
More information about the Python-list
mailing list