1

Using this code:

import java.io.*;
import java.util.*;

import javax.mail.*;

public class Mbox {
    public static void main(String[] args) {
        Properties properties = new Properties();
        properties.setProperty("mail.store.protocol", "mstor");
        properties.setProperty("mstor.mbox.metadataStrategy", "none");
        properties.setProperty("mstor.mbox.cacheBuffers", "disabled");
        properties.setProperty("mstor.cache.disabled", "true");
        properties.setProperty("mstor.mbox.bufferStrategy", "mapped");
        properties.setProperty("mstor.metadata", "disabled");

        Session session = Session.getDefaultInstance(properties);

        try {
            Store store = session.getStore(new URLName("mstor:C:/INBOX"));
            store.connect();
            Folder inbox = store.getDefaultFolder().getFolder("inbox");
            inbox.open(Folder.READ_ONLY);
            Message m = inbox.getMessage(1);

        } catch (Exception e) {
            e.printStackTrace();

        }

        }
    }

I am trying to setup an mbox reading program in java. I have tried both on Linux and Windows but every time I get the exception javax.mail.NoSuchProviderException: No provider for mstor on session.getStore("mstor:C:/INBOX"). I searched for a while and made the properties file as shown above but still the error persited.

javax.mail.NoSuchProviderException: No provider for mstor
    at javax.mail.Session.getProvider(Session.java:473)
    at javax.mail.Session.getStore(Session.java:547)
    at Mbox.main(Mbox.java:23)

What am I doing wrong?

Charlie
  • 978
  • 1
  • 7
  • 27
Aditya Raman
  • 309
  • 8
  • 19
  • That URL doesn't look right at all to me. Where did you get it from? – duffymo Jan 08 '15 at 14:18
  • If you have tried it on Linux, are you sure you changed `c:/INBOX` ? – Charlie Jan 08 '15 at 14:37
  • @duffymo I created a folder named INBOX in C: and kept a sample mbox file in it. So the url should be like that. – Aditya Raman Jan 08 '15 at 17:17
  • @Charlie i am right now using this code on windows system. – Aditya Raman Jan 08 '15 at 17:18
  • I don't believe that's a valid URL. http://en.wikipedia.org/wiki/Uniform_resource_locator – duffymo Jan 08 '15 at 17:29
  • @duffymo: Thats a url for store . see for understaning [stack overflow answer](http://stackoverflow.com/questions/7710543/how-to-read-mbox-email-messages-using-mstor) – Aditya Raman Jan 08 '15 at 19:45
  • What are you setting your classpath to? Does it include the mstor jar file? – Bill Shannon Jan 09 '15 at 03:28
  • @BillShannon : yes I missed including that jar in classpath of my project and apart from it common loggings was also required. That fixed it. Thanks a tonn!! :) – Aditya Raman Jan 09 '15 at 08:12
  • @BillShannon : Can you help me with understanding the property fields which have been set up in this code. I just copied from another answer and there also no explanation was supplied for these prop settings. – Aditya Raman Jan 09 '15 at 09:08
  • I really don't know anything about mstor, but I found some documentation of the properties [here](http://sourceforge.net/p/mstor/mercurial/ci/default/tree/README?format=raw). You might also want to look at the [JavaMail mbox provider](https://java.net/projects/javamail/pages/MboxStore). – Bill Shannon Jan 09 '15 at 20:44

0 Answers0