1 package SnowMailClient.view.actions; 2 3 import SnowMailClient.model.*; 4 import SnowMailClient.model.accounts.*; 5 import snow.utils.storage.*; 6 import SnowMailClient.view.*; 7 import SnowMailClient.SnowMailClientApp; 8 import SnowMailClient.Language.Language; 9 10 import java.awt.*; 11 import java.io.*; 12 import java.awt.event.*; 13 import javax.swing.*; 14 import javax.swing.event.*; 15 import javax.swing.tree.*; 16 17 19 public class ImportMailMessage extends AbstractAction 20 { 21 FolderView folderView; 22 23 public ImportMailMessage(FolderView folderView) 24 { 25 super(Language.translate("Import Mail message")); 26 this.folderView = folderView; 27 28 34 35 putValue(AbstractAction.SHORT_DESCRIPTION, 36 Language.translate("Import a mail message from a file in the current mail folder")); 37 38 } 40 public void actionPerformed(ActionEvent e) 41 { 42 String defDir = SnowMailClientApp.getInstance().getProperties().getProperty("ImportMailMessage_dir", System.getProperty("user.home", "")); 43 JFileChooser fileLoad = new JFileChooser(defDir); 44 fileLoad.setDialogTitle("Select the mail file(s) to import"); 45 fileLoad.setMultiSelectionEnabled(true); 46 47 int rep = fileLoad.showOpenDialog(SnowMailClientApp.getInstance()); 48 if(rep==JFileChooser.APPROVE_OPTION) 49 { 50 File[] files = fileLoad.getSelectedFiles(); 51 for(int i=0; i<files.length; i++) 52 { 53 if(i==0) 54 { 55 SnowMailClientApp.getInstance().getProperties().setProperty("ImportMailMessage_dir", 56 files[0].getParent()); 57 } 58 try 59 { 60 byte[] content = FileUtils.getFileContent(files[i]); 61 MailMessage mess = new MailMessage(); 62 mess.parse(new String (content)); 63 mess.setEditable(true); 64 65 folderView.getMailFolder().addMessage(mess); 66 } 67 catch(Exception ex) 68 { 69 JOptionPane.showMessageDialog( 70 SnowMailClientApp.getInstance(), 71 "Error: "+ex.getMessage(), 72 "Error importing message", 73 JOptionPane.ERROR_MESSAGE); 74 } 75 76 } 77 } 78 79 80 81 } 82 83 84 85 } | Popular Tags |