1,105,399 Community Members

parse emails from mailbox file in script

Member Avatar
hemanshurpatel
Newbie Poster
24 posts since Aug 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,

I need to fetch mail body from the local stored mailbox file.
I'm using fetchmail and procmail to download emails from IMAP server and filterout unwanted one.
From the list of emails, I want to process one by one and get their body and store it.

the format of mailbox file would be something like this

From hemanshu  Fri Aug 30 11:25:25 2013
Return-Path: <hemanshu@example.com>
Received: from mailgate.example.com [xx.xx.xx.xx]
        by lt-hemanshu.client.example.com with IMAP (fetchmail-6.3.22)
        for <hemanshu@localhost> (single-drop); Fri, 30 Aug 2013 11:25:25 -0400 (EDT)
Received: via tmail-2000(13) for user1; Tue, 27 Aug 2013 16:27:25 -0400 (EDT)
Received: from mail.example.com (mail.example.com [cc.cc.cc.cc])
        by gmail.example.com (8.13.8+Sun/8.11.6) with ESMTP id r7RKRPHJ008408
        for <user1@gmail.example.com>; Tue, 27 Aug 2013 16:27:25 -0400 (EDT)
Received: by mail.example.com (Postfix)
        id 1A674E277B; Tue, 27 Aug 2013 16:26:33 -0400 (EDT)
Delivered-To: user1@example.com
Received: from njvexg1.example.com (njvexg1.example.com [yy.yy.yy.yy])
        by mail.example.com (Postfix) with ESMTP id 18A36E2534
        for <user1@example.com>; Tue, 27 Aug 2013 16:26:33 -0400 (EDT)
Received: from [xx.xx.xx.xx] (vv.vv.vv.vv) by
 njvexg1.example.com (xx.xx.xx.xx) with Microsoft SMTP Server id
 8.3.327.1; Tue, 27 Aug 2013 16:27:20 -0400
Message-ID: <521D0BA7.7040100@example.com>
Date: Tue, 27 Aug 2013 16:27:19 -0400
From: Hemanshu Patel <hemanshu@example.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130805 Thunderbird/17.0.8
MIME-Version: 1.0
To: <user1@example.com>
Subject: anything goes here
Content-Type: text/plain; charset="ISO-8859-1"; format=flowed
Content-Transfer-Encoding: 7bit

Any email body goes here.
email body can span more than one line


From hemanshu  Fri Aug 30 11:25:25 2013
Return-Path: <hemanshu@example.com>
Received: from mailgate.example.com [xx.xx.xx.xx]
        by lt-hemanshu.client.example.com with IMAP (fetchmail-6.3.22)
        for <hemanshu@localhost> (single-drop); Fri, 30 Aug 2013 11:25:25 -0400 (EDT)
Received: via tmail-2000(13) for user1; Tue, 27 Aug 2013 16:27:25 -0400 (EDT)
Received: from mail.example.com (mail.example.com [cc.cc.cc.cc])
        by gmail.example.com (8.13.8+Sun/8.11.6) with ESMTP id r7RKRPHJ008408
        for <user1@gmail.example.com>; Tue, 27 Aug 2013 16:27:25 -0400 (EDT)
Received: by mail.example.com (Postfix)
        id 1A674E277B; Tue, 27 Aug 2013 16:26:33 -0400 (EDT)
Delivered-To: user1@example.com
Received: from njvexg1.example.com (njvexg1.example.com [yy.yy.yy.yy])
        by mail.example.com (Postfix) with ESMTP id 18A36E2534
        for <user1@example.com>; Tue, 27 Aug 2013 16:26:33 -0400 (EDT)
Received: from [xx.xx.xx.xx] (vv.vv.vv.vv) by
 njvexg1.example.com (xx.xx.xx.xx) with Microsoft SMTP Server id
 8.3.327.1; Tue, 27 Aug 2013 16:27:20 -0400
Message-ID: <521D0BA7.7040100@example.com>
Date: Tue, 27 Aug 2013 16:27:19 -0400
From: Hemanshu Patel <hemanshu@example.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130805 Thunderbird/17.0.8
MIME-Version: 1.0
To: <user1@example.com>
Subject: anything goes here
Content-Type: text/plain; charset="ISO-8859-1"; format=flowed
Content-Transfer-Encoding: 7bit

Any email body goes here.
email body can span more than one line


From hemanshu  Fri Aug 30 11:25:25 2013
Return-Path: <hemanshu@example.com>
Received: from mailgate.example.com [xx.xx.xx.xx]
        by lt-hemanshu.client.example.com with IMAP (fetchmail-6.3.22)
        for <hemanshu@localhost> (single-drop); Fri, 30 Aug 2013 11:25:25 -0400 (EDT)
Received: via tmail-2000(13) for user1; Tue, 27 Aug 2013 16:27:25 -0400 (EDT)
Received: from mail.example.com (mail.example.com [cc.cc.cc.cc])
        by gmail.example.com (8.13.8+Sun/8.11.6) with ESMTP id r7RKRPHJ008408
        for <user1@gmail.example.com>; Tue, 27 Aug 2013 16:27:25 -0400 (EDT)
Received: by mail.example.com (Postfix)
        id 1A674E277B; Tue, 27 Aug 2013 16:26:33 -0400 (EDT)
Delivered-To: user1@example.com
Received: from njvexg1.example.com (njvexg1.example.com [yy.yy.yy.yy])
        by mail.example.com (Postfix) with ESMTP id 18A36E2534
        for <user1@example.com>; Tue, 27 Aug 2013 16:26:33 -0400 (EDT)
Received: from [xx.xx.xx.xx] (vv.vv.vv.vv) by
 njvexg1.example.com (xx.xx.xx.xx) with Microsoft SMTP Server id
 8.3.327.1; Tue, 27 Aug 2013 16:27:20 -0400
Message-ID: <521D0BA7.7040100@example.com>
Date: Tue, 27 Aug 2013 16:27:19 -0400
From: Hemanshu Patel <hemanshu@example.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130805 Thunderbird/17.0.8
MIME-Version: 1.0
To: <user1@example.com>
Subject: anything goes here
Content-Type: text/plain; charset="ISO-8859-1"; format=flowed
Content-Transfer-Encoding: 7bit

Any email body goes here.
email body can span more than one line

In bash script I want to parse this file, first divide them in single email and then get their body and store it in saperate file.

I'm not that great in bash scripting as I am a C/C++ guy.
Can anyone help me please?

Hemanshu

Member Avatar
hemanshurpatel
Newbie Poster
24 posts since Aug 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

NVM

I managed via some laboursome parsing, line by line.

Question Self-Answered as of 7 Months Ago
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article