-2

I'm using Linux OS. My objective was to convert pst file to mbox & read the data using mailbox library from python. I used readpst to convert and store in /tmp/ for temporary purpose

readpst -rS input.pst -o /tmp/

"readpst" has extracted/converted as expected. Now I wanted to read the mail using mailbox library.

I have tried the following code.

import mailbox
mbox = mailbox.mbox('/tmp/Personal Folder/Inbox/mbox')
for message in mbox:
    print message['subject']

But it was not working coz, no mbox file was not found. While using readpst tool it was not created - "mbox" file.

I've tried to read mbox using "mail" as

mail -f /tmp/Personal Folder/Inbox and it worked. But, I wanted to read all the subject using python.

jOSe
  • 687
  • 11
  • 22
  • Your question doesn't make sense. Does the file `/tmp/Personal Folder/Inbox/mbox` actually exist? – MattDMo Jul 18 '15 at 05:29
  • Yes, after executing "readpst" it'll be automatically created. – jOSe Jul 18 '15 at 05:37
  • "aromatically" do what? Have you actually run the command `ls -l "/tmp/Personal Folder/Inbox"` to confirm that `Inbox` is a directory and a file called `mbox` exists within it? – MattDMo Jul 18 '15 at 05:38
  • Hi, I've used `readpst -r file.pst -o /tmp/` which created mbox file in respective folders like Inbox, Junk E mail, outpost, draft. @PeterWood Yes mbox exist. Using mailbox library how to get message body and attachements? – jOSe Jul 18 '15 at 05:49
  • @jOSe if `/tmp/Personal Folder/Inbox/mbox` **actually** exists as a file on disk, then your code should work. If it's failing with an error saying the mbox file was not found, then `/tmp/Personal Folder/Inbox/mbox` *must **not** exist*. Please [edit] your question (don't post in the comments) and add the **full and complete** text of the traceback you get when running your code above. – MattDMo Jul 18 '15 at 06:18
  • @MattDMo after changing the `readpst -rS` to `readpst -r` the "mbox" file got created. I 've used the python code in question to extract subject, message body, to, date information. But unable to extract attachment. While using `readpst -S` it extracts attachment too. – jOSe Jul 18 '15 at 06:37
  • @jOSe good for you. If you have a new question about extracting and saving attachments, then ask it *as a new question*. Don't change an existing question to be about something completely different. But first, I strongly suggest reading through the **entire** [documentation](https://docs.python.org/2/library/mailbox.html) to find the answer. Very briefly scanning through, you'll likely need other modules like [`email.message`](https://docs.python.org/2/library/email.message.html#module-email.message). – MattDMo Jul 18 '15 at 06:43
  • @jOSe By the way, if you'd just done what I suggested at first to confirm the presence of the `mbox` file, maybe you wouldn't have wasted an hour... – MattDMo Jul 18 '15 at 06:46

1 Answers1

0

Use

readpst -r file.pst -o /tmp/ to create mbox file in respective file. rather than

readpst -rS file.pst -o /tmp/

jOSe
  • 687
  • 11
  • 22