extract gmail message body from mbox file

i am trying to do this
http://www.ripariandata.com/blog/how-to-export-your-gmail-to-excel

but also extract the message of each email in gmail
right now just getting the sender and reciever data and not the actual content of the message

not sure how to do this either in this code or via this method-
http://stackoverflow.com/questions/7166922/extracting-the-body-of-an-email-from-mbox-file-decoding-it-to-plain-text-regard
finnstoneAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Walter RitzelSenior Software EngineerCommented:
I have looked into your 2 links, and it was not clear to me how to help you, so I search again on the web and found this link:
https://mail.python.org/pipermail/tutor/2008-September/064272.html
It seems to be good and clarifies that you will need to use a recursive approach to load the messages (body).
import mailbox

def showMbox(mboxPath):
    box = mailbox.mbox(mboxPath)
    for msg in box:
        print msg['Subject']
        showPayload(msg)

        print
        print '**********************************'
        print


def showPayload(msg):
    payload = msg.get_payload()

    if msg.is_multipart():
        div = ''
        for subMsg in payload:
            print div
            showPayload(subMsg)
            div = '------------------------------'
    else:
        print msg.get_content_type()
        print payload[:200]


if __name__ == '__main__':
    showMbox('mbox.txt')

Open in new window

mbox.txt

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
finnstoneAuthor Commented:
thanks Walter. is that python?
Walter RitzelSenior Software EngineerCommented:
Yes, it is.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

finnstoneAuthor Commented:
will this export the messages into csv. thats what i was looking for
Walter RitzelSenior Software EngineerCommented:
This give you the structure on how to get and read a mbox file. Now, you just need to write the piece to write it down to a CSV. Unless I did not understood and you want us to code all for you.
finnstoneAuthor Commented:
yes I do need help doing that, much appreciated!
Walter RitzelSenior Software EngineerCommented:
Well, let's do something: the purpose here is not deliver a full solution to you, but help you to learn how to solve the issue. So, why don't you publish your code so far, with samples and such and we work on top of it together?
finnstoneAuthor Commented:
wow amazing
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CSS

From novice to tech pro — start learning today.