1 package org.columba.mail.folder.command; 17 18 import java.io.BufferedInputStream ; 19 import java.io.BufferedOutputStream ; 20 import java.io.FileOutputStream ; 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 import java.io.OutputStream ; 24 import java.text.MessageFormat ; 25 26 import javax.swing.JOptionPane ; 27 28 import org.columba.api.command.ICommandReference; 29 import org.columba.api.command.IWorkerStatusController; 30 import org.columba.core.command.Command; 31 import org.columba.core.gui.frame.FrameManager; 32 import org.columba.mail.command.IMailFolderCommandReference; 33 import org.columba.mail.folder.IMailbox; 34 import org.columba.mail.util.MailResourceLoader; 35 36 43 public class ExportFolderCommand extends Command { 44 45 protected Object [] destUids; 46 47 50 public ExportFolderCommand(ICommandReference reference) { 51 super(reference); 52 } 53 54 59 public void execute(IWorkerStatusController worker) throws Exception { 60 IMailFolderCommandReference r = (IMailFolderCommandReference) getReference(); 62 63 OutputStream os = null; 64 65 try { 66 os = new BufferedOutputStream (new FileOutputStream (r.getDestFile())); 68 69 int counter = 0; 70 IMailbox srcFolder; 71 Object [] uids; 72 InputStream in; 73 int read; 74 byte[] buffer = new byte[1024]; 75 76 srcFolder = (IMailbox) r.getSourceFolder(); 78 79 uids = srcFolder.getUids(); 81 82 worker.setProgressBarMaximum(uids.length); 84 worker.setProgressBarValue(0); 85 86 for (int j = 0; (j < uids.length) && !worker.cancelled(); j++) { 88 in = new BufferedInputStream (srcFolder 90 .getMessageSourceStream(uids[j])); 91 92 os.write(new String ("From \r\n").getBytes()); 94 95 while ((read = in.read(buffer, 0, buffer.length)) > 0) { 97 os.write(buffer, 0, read); 98 } 99 100 try { 101 in.close(); 102 } catch (IOException ioe_) { 103 } 104 105 os.write(new String ("\r\n").getBytes()); 107 108 os.flush(); 109 110 worker.setProgressBarValue(j); 111 counter++; 112 } 113 114 if (worker.cancelled()) { 116 worker.setDisplayText(MailResourceLoader.getString("statusbar", 117 "message", "export_messages_cancelled")); 118 } else { 119 worker.setDisplayText(MessageFormat.format(MailResourceLoader 120 .getString("statusbar", "message", 121 "export_messages_success"), 122 new Object [] { Integer.toString(counter) })); 123 } 124 } catch (IOException ioe) { 125 JOptionPane.showMessageDialog(FrameManager.getInstance() 126 .getActiveFrame(), MailResourceLoader.getString( 127 "statusbar", "message", "err_export_messages_msg"), 128 MailResourceLoader.getString("statusbar", "messages", 129 "err_export_messages_title"), 130 JOptionPane.ERROR_MESSAGE); 131 } finally { 132 try { 133 if (os != null) { 135 os.close(); 136 } 137 } catch (IOException ioe) { 138 } 139 } 140 } 141 } | Popular Tags |