Last active
August 29, 2015 14:12
-
-
Save dlangille/0d01a703af266b0f3022 to your computer and use it in GitHub Desktop.
Mail recovery, proof of concept
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I think this is my solution, based on http://giantdorks.org/alain/resend-mail-thats-locally-stored-in-a-mbox-format-on-a-linux-box-to-a-working-email-address/ | |
export myemail=foo@example.org | |
cat msg.example | | |
formail -k \ | |
-X From: \ | |
-X Subject: \ | |
-X Message-Id: \ | |
-X Date: \ | |
-X To: \ | |
-I "To: $myemail" \ | |
-s /usr/sbin/sendmail -t -f $myemail | |
This is an email which I have pulled out of the mbox file as an example. This shows the full headers, with hostnames and IP addresses obscured. | |
$ cat msg.example | |
From mailarchives Sat Jan 3 00:00:04 2015 | |
>From MAILER-DAEMON Sat Jan 3 00:00:04 2015 | |
Return-Path: <> | |
X-Original-To: mailarchives@mailarchiving.example.org | |
Delivered-To: mailarchives@tallboy.example.org | |
Received: from mailjail.langille.org (mailjail.langille.org [10.0.0.1]) | |
by tallboy.example.org (Postfix) with ESMTPS id 1B5B81C51B1C | |
for <mailarchives@mailarchiving.example.org>; Sat, 3 Jan 2015 00:00:04 +0000 (UTC) | |
Received: by mailjail.langille.org (Postfix, from userid 1002) | |
id D36B74AF9; Sat, 3 Jan 2015 00:00:03 +0000 (UTC) | |
X-Original-To: dan@mailjail.langille.org | |
Delivered-To: dan@mailjail.langille.org | |
Received: from supernews.example.org (supernews.example.org [10.22.0.1]) | |
by mailjail.langille.org (Postfix) with ESMTPS id C12744AF7 | |
for <dan@mailjail.langille.org>; Sat, 3 Jan 2015 00:00:03 +0000 (UTC) | |
Received: from supernews.example.org (localhost [127.0.0.1]) | |
by supernews.example.org (Postfix) with ESMTP id 219E017081 | |
for <dan@mailjail.langille.org>; Sat, 3 Jan 2015 00:00:03 +0000 (UTC) | |
X-Virus-Scanned: amavisd-new at example.org | |
Received: from supernews.example.org ([127.0.0.1]) | |
by supernews.example.org (supernews.example.org [127.0.0.1]) (amavisd-new, port 10024) | |
with ESMTP id nbmndfgsF8fF for <dan@mailjail.langille.org>; | |
Sat, 3 Jan 2015 00:00:02 +0000 (UTC) | |
Received: by supernews.example.org (Postfix, from userid 1001) | |
id EAEEB1707F; Sat, 3 Jan 2015 00:00:02 +0000 (UTC) | |
X-Original-To: dan@localhost.example.org | |
Delivered-To: dan@localhost.example.org | |
Received: from supernews.example.org (localhost [127.0.0.1]) | |
by supernews.example.org (Postfix) with ESMTP id DD5651707D | |
for <dan@localhost.example.org>; Sat, 3 Jan 2015 00:00:02 +0000 (UTC) | |
X-Virus-Scanned: amavisd-new at example.org | |
Received: from supernews.example.org ([127.0.0.1]) | |
by supernews.example.org (supernews.example.org [127.0.0.1]) (amavisd-new, port 10024) | |
with ESMTP id MrK1GAVHswg3 for <dan@localhost.example.org>; | |
Sat, 3 Jan 2015 00:00:02 +0000 (UTC) | |
Received: by supernews.example.org (Postfix, from userid 1001) | |
id 8F88F1707C; Sat, 3 Jan 2015 00:00:02 +0000 (UTC) | |
To: dan@langille.org | |
Subject: FreshPorts users | |
Message-Id: <20150103000002.8F88F1707C@supernews.example.org> | |
Date: Sat, 3 Jan 2015 00:00:02 +0000 (UTC) | |
From: dan@supernews.example.org (Dan Langille) | |
there are 2 arguments | |
sql is select id, name, email, ip_address, firstlogin | |
from users | |
where date_trunc('day', firstlogin) = '2015-01-02' | |
order by id | |
msgbody = | |
If I run this through the magic, we get this: | |
export myemail=foo@example.org | |
$ cat msg.example | | |
formail -k \ | |
-X From: \ | |
-X Subject: \ | |
-X Message-Id: \ | |
-X Date: \ | |
-X To: \ | |
-I "To: $myemail" | |
Subject: FreshPorts users | |
Message-Id: <20150103000002.8F88F1707C@supernews.example.org> | |
Date: Sat, 3 Jan 2015 00:00:02 +0000 (UTC) | |
From: dan@supernews.example.org (Dan Langille) | |
To: foo@example.org | |
there are 2 arguments | |
sql is select id, name, email, ip_address, firstlogin | |
from users | |
where date_trunc('day', firstlogin) = '2015-01-02' | |
order by id | |
msgbody = | |
We can then email that message directly back to my mailbox. That's what the "-s /usr/sbin/sendmail -t -f $myemail" is for. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment