Index: plugins/src/org/blojsom/plugin/moblog/MoblogPlugin.java
===================================================================
RCS file: /cvsroot/blojsom/blojsom-2.0/plugins/src/org/blojsom/plugin/moblog/MoblogPlugin.java,v
retrieving revision 1.20
diff -u -w -r1.20 MoblogPlugin.java
--- plugins/src/org/blojsom/plugin/moblog/MoblogPlugin.java	24 Nov 2004 15:31:23 -0000	1.20
+++ plugins/src/org/blojsom/plugin/moblog/MoblogPlugin.java	30 Dec 2004 15:32:22 -0000
@@ -101,7 +101,7 @@
     /**
      * Default store
      */
-    private static final String POP3_STORE = "pop3";
+    private static final String DEFAULT_MESSAGE_STORE = "pop3";
 
     /**
      * Default poll time (10 minutes)
@@ -119,6 +119,11 @@
     public static final String PLUGIN_MOBLOG_POLL_TIME = "plugin-moblog-poll-time";
 
     /**
+     * Moblog configuration parameter for message store provider
+     */
+    public static final String PLUGIN_MOBLOG_STORE_PROVIDER = "plugin-moblog-store-provider";
+
+    /**
      * Default moblog authorization properties file which lists valid e-mail addresses who can moblog entries
      */
     public static final String DEFAULT_MOBLOG_AUTHORIZATION_FILE = "moblog-authorization.properties";
@@ -175,11 +180,12 @@
 
     private int _pollTime;
 
-    private Session _popSession;
+    private Session _storeSession;
     private boolean _finished = false;
     private MailboxChecker _checker;
     private ServletConfig _servletConfig;
     private BlojsomConfiguration _blojsomConfiguration;
+    private String _storeProvider;
 
     private BlojsomFetcher _fetcher;
 
@@ -231,6 +237,11 @@
             }
         }
 
+        _storeProvider = servletConfig.getInitParameter(PLUGIN_MOBLOG_STORE_PROVIDER);
+        if (BlojsomUtils.checkNullOrBlank(_storeProvider)) {
+            _storeProvider = DEFAULT_MESSAGE_STORE;
+        }
+
         _servletConfig = servletConfig;
         _blojsomConfiguration = blojsomConfiguration;
         _checker = new MailboxChecker();
@@ -241,7 +252,7 @@
             if (hostname.startsWith("java:comp/env")) {
                 try {
                     Context context = new InitialContext();
-                    _popSession = (Session) context.lookup(hostname);
+                    _storeSession = (Session) context.lookup(hostname);
                 } catch (NamingException e) {
                     _logger.error(e);
                     throw new BlojsomPluginException(e);
@@ -253,9 +264,9 @@
                 Properties props = new Properties();
                 props.put(SESSION_NAME, hostname);
                 if (BlojsomUtils.checkNullOrBlank(username) || BlojsomUtils.checkNullOrBlank(password)) {
-                    _popSession = Session.getDefaultInstance(props, null);
+                    _storeSession = Session.getDefaultInstance(props, null);
                 } else {
-                    _popSession = Session.getDefaultInstance(props, new SimpleAuthenticator(username, password));
+                    _storeSession = Session.getDefaultInstance(props, new SimpleAuthenticator(username, password));
                 }
             }
         }
@@ -331,7 +342,7 @@
             Store store = null;
             String subject = null;
             try {
-                store = _popSession.getStore(POP3_STORE);
+                store = _storeSession.getStore(_storeProvider);
                 store.connect(mailbox.getHostName(), mailbox.getUserId(), mailbox.getPassword());
 
                 // -- Try to get hold of the default folder --
@@ -454,10 +465,6 @@
 
                                         if (imageMimeTypes.containsKey(type)) {
                                             _logger.debug("Creating image of type: " + type);
-                                            InputStream is = bp.getInputStream();
-                                            byte[] imageFile = new byte[is.available()];
-                                            is.read(imageFile, 0, is.available());
-                                            is.close();
                                             String outputFilename =
                                                     BlojsomUtils.digestString(bp.getFileName() + "-" + new Date().getTime());
                                             String extension = BlojsomUtils.getFileExtension(bp.getFileName());
@@ -467,10 +474,7 @@
 
                                             _logger.debug("Writing to: " + mailbox.getOutputDirectory() + File.separator +
                                                     outputFilename + "." + extension);
-                                            FileOutputStream fos = new
-                                                    FileOutputStream(new File(mailbox.getOutputDirectory() + File.separator + outputFilename + "." + extension));
-                                            fos.write(imageFile);
-                                            fos.close();
+                                            MoblogPluginUtils.saveFile(mailbox.getOutputDirectory() + File.separator + outputFilename + "." + extension, bp.getInputStream());
                                             String baseurl = mailbox.getBlogUser().getBlog().getBlogBaseURL();
                                             entry.append("<p /><img src=\"").append(baseurl).
                                                     append(mailbox.getUrlPrefix()).
@@ -479,10 +483,6 @@
                                                     append("\" />");
                                         } else if (attachmentMimeTypes.containsKey(type)) {
                                             _logger.debug("Creating attachment of type: " + type);
-                                            InputStream is = bp.getInputStream();
-                                            byte[] attachmentFile = new byte[is.available()];
-                                            is.read(attachmentFile, 0, is.available());
-                                            is.close();
                                             String outputFilename =
                                                     BlojsomUtils.digestString(bp.getFileName() + "-" + new Date().getTime());
                                             String extension = BlojsomUtils.getFileExtension(bp.getFileName());
@@ -492,10 +492,7 @@
 
                                             _logger.debug("Writing to: " + mailbox.getOutputDirectory() + File.separator +
                                                     outputFilename + "." + extension);
-                                            FileOutputStream fos = new
-                                                    FileOutputStream(new File(mailbox.getOutputDirectory() + File.separator + outputFilename + "." + extension));
-                                            fos.write(attachmentFile);
-                                            fos.close();
+                                            MoblogPluginUtils.saveFile(mailbox.getOutputDirectory() + File.separator + outputFilename + "." + extension, bp.getInputStream());
                                             String baseurl = mailbox.getBlogUser().getBlog().getBlogBaseURL();
                                             entry.append("<p /><a href=\"").append(baseurl).append(mailbox.getUrlPrefix()).append(outputFilename + "." + extension).append("\">").append(bp.getFileName()).append("</a>");
                                         } else if (textMimeTypes.containsKey(type)) {
Index: plugins/src/org/blojsom/plugin/moblog/MoblogPluginUtils.java
===================================================================
RCS file: /cvsroot/blojsom/blojsom-2.0/plugins/src/org/blojsom/plugin/moblog/MoblogPluginUtils.java,v
retrieving revision 1.1
diff -u -w -r1.1 MoblogPluginUtils.java
--- plugins/src/org/blojsom/plugin/moblog/MoblogPluginUtils.java	14 Jun 2004 00:27:16 -0000	1.1
+++ plugins/src/org/blojsom/plugin/moblog/MoblogPluginUtils.java	30 Dec 2004 15:32:22 -0000
@@ -41,7 +41,10 @@
 import org.blojsom.util.BlojsomUtils;
 
 import javax.servlet.ServletConfig;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.HashMap;
@@ -240,4 +243,31 @@
 
         return mailbox;
     }
+
+    public static int saveFile(String filename, InputStream input) throws IOException {
+        int count = 0;
+        if (filename == null) {
+            filename = File.createTempFile("xx", ".out").getName();
+        }
+
+        // Do no overwrite existing file
+        File file = new File(filename);
+        for (int i = 0; file.exists(); i++) {
+            file = new File(filename + i);
+        }
+        FileOutputStream fos = new FileOutputStream(file);
+        BufferedOutputStream bos = new BufferedOutputStream(fos);
+
+        BufferedInputStream bis = new BufferedInputStream(input);
+        int aByte;
+        while ((aByte = bis.read()) != -1) {
+            bos.write(aByte);
+            count++;
+        }
+        bos.flush();
+        bos.close();
+        bis.close();
+
+        return count;
+    }
 }
