Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.python > #4320

[Python-de] Datum aus Mails parsen

From Florian Lindner <mailinglists@xgm.de>
Newsgroups de.comp.lang.python
Subject [Python-de] Datum aus Mails parsen
Date 2016-03-22 20:59 +0100
Message-ID <mailman.21.1458677307.2244.python-de@python.org> (permalink)

Show all headers | View raw


Hallo,

ich will das Datum einer Mail rausfinden, ob es das Sende- oder Empfangsdatum 
ist, oder eins der Stationen in der Mitte ist egal.

Nun habe ich mir mal eine beliebige Mail rausgegriffen:

From someone@gmail.com Fri Feb 05 09:09:11 2016
Received: from ipvsmail.informatik.uni-stuttgart.de
        by hermes.informatik.uni-stuttgart.de (Dovecot) with LMTP id 
842rLx9mtFbVeAAAqVsIVA
        for <user@ipvs.uni-stuttgart.de>; Fri, 05 Feb 2016 10:09:12 +0100
Received: from mx3.informatik.uni-stuttgart.de (mailgw.informatik.uni-
stuttgart.de [129.69.211.42])
        by ipvsmail.informatik.uni-stuttgart.de (Postfix) with ESMTP id 
D3111EA3
        for <somereceiver@ipvsmail.informatik.uni-stuttgart.de>; Fri,  5 Feb 
2016 10:09:12 +0100 (CET)
Received: by mx3.informatik.uni-stuttgart.de (Postfix, from userid 65534)
        id BD6DB6251; Fri,  5 Feb 2016 10:09:12 +0100 (CET)
Received: from mail-lf0-f52.google.com (mail-lf0-f52.google.com 
[209.85.215.52])
        (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
        (No client certificate requested)
        by mx3.informatik.uni-stuttgart.de (Postfix) with ESMTPS id E6D546249
        for <somereceiver@ipvs.uni-stuttgart.de>; Fri,  5 Feb 2016 10:09:11 
+0100 (CET)
Received: by mail-lf0-f52.google.com with SMTP id 78so52976351lfy.3
        for <somereceiver@ipvs.uni-stuttgart.de>; Fri, 05 Feb 2016 01:09:11 
-0800 (PST)
X-Received: by 10.25.42.18 with SMTP id q18mr5524069lfq.151.1454663351309;
 Fri, 05 Feb 2016 01:09:11 -0800 (PST)
Received: by 10.25.145.21 with HTTP; Fri, 5 Feb 2016 01:09:11 -0800 (PST)
Received: by 10.25.145.21 with HTTP; Fri, 5 Feb 2016 01:09:11 -0800 (PST)
Date: Fri, 5 Feb 2016 10:09:11 +0100

Ein wenig habe ich schon irrelevante Infos rausgenommen.

Probleme die ich sehe ist a) die Zuverlässigkeit des Datums und b) die 
Standardisierung des Formates.

Der Date Header springt natürlich sofort ins Auge, aber ich denke nicht, dass 
der sonderlich zuverlässig ist. Regelmäßig bekomme ich Spam mit unbekannten 
Datum oder Datum in der Zukunft. Außerdem habe ich bei ersten Testläufen auch 
verschiedene Formate gesehen (z.B. die Zeit ohne Sekunden)

Nun frage ich mich, was da am zuverlässigsten ist? Die erste Zeile From gibt 
es offensichtlich auch nicht bei allen Mails.

Sollte man einfach den ersten Received Header nehmen, am ";" trennen und dann 
datetime.strptime mit einen entsprechenden Format String drauf los lassen?

Was denkt Ihr, ist das Beste?

Viele Grüße,
Florian

Back to de.comp.lang.python | Previous | Next | Find similar


Thread

[Python-de] Datum aus Mails parsen Florian Lindner <mailinglists@xgm.de> - 2016-03-22 20:59 +0100

csiph-web