From owner-freebsd-questions@FreeBSD.ORG Mon Mar 24 18:56:55 2008 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9AE0D106566C for ; Mon, 24 Mar 2008 18:56:55 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id C1DF88FC15 for ; Mon, 24 Mar 2008 18:56:54 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (vader.bytemobile-rio.ondsl.gr [83.235.57.37]) (authenticated bits=128) by igloo.linux.gr (8.14.2/8.14.2/Debian-3) with ESMTP id m2OIuTFU021463 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 24 Mar 2008 20:56:44 +0200 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.2/8.14.2) with ESMTP id m2OIuNWM002306; Mon, 24 Mar 2008 20:56:23 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.2/8.14.2/Submit) id m2OIuNTX002305; Mon, 24 Mar 2008 20:56:23 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) From: Giorgos Keramidas To: Robert Huff References: <18407.62370.787768.503114@jerusalem.litteratus.org> Date: Mon, 24 Mar 2008 20:56:23 +0200 In-Reply-To: <18407.62370.787768.503114@jerusalem.litteratus.org> (Robert Huff's message of "Mon, 24 Mar 2008 14:32:02 -0400") Message-ID: <874paw3q94.fsf@kobe.laptop> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-MailScanner-ID: m2OIuTFU021463 X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.977, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.42, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: questions@freebsd.org Subject: Email processing in Python (was: e-mail processing in C) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Mar 2008 18:56:55 -0000 On Mon, 24 Mar 2008 14:32:02 -0400, Robert Huff wrote: > I need to write a quick and not-too-dirty C program to process some > e-mail. (Including dealing with mbox files.) > > Is there a standard library to do this? Respectfully, No, there's no library for `email processing' in the C standard. You can probably find a lot of non-standard ones, by Googling however :) It's worth writing that plain C is the wrong language for this sort of thing, if you ask me. There are excellent high-level libraries in Perl, and Python to do this sort of thing. Email processing is going to require a log of string processing, and C is notoriously 'tricky' for this sort of thing. As an example of the expressiveness of using a higher level language, you can display the authors of all the messages in a UNIX mailbox with the following short Python script: import mailbox m = mailbox.mbox('/home/keramida/mbox') for message in m: author = m['from] print author This is not just a `readable pseudo-code-like example'. It's *real* Python code, that you can run _now_ in your Python shell. To perform a similar task in plain C you will need several dozens of lines of code, and it won't necessarily be as readable. It _may_ be faster, in some cases, but it will probably won't be as 'safe'.