Exemplo n.º 1
0
  /** {@inheritDoc} */
  @Override
  public String runImport(
      final GnucashWritableFile aWritableModel, final GnucashWritableAccount aCurrentAccount)
      throws Exception {
    try {
      Properties props = System.getProperties();
      Session session = Session.getDefaultInstance(props, null);
      Store store = session.getStore("imap");
      String server = aWritableModel.getUserDefinedAttribute("imap.server");
      if (server == null) {
        server =
            JOptionPane.showInputDialog(
                "imap-server: (can be changed later in the root-account properties.)");
        aWritableModel.setUserDefinedAttribute("imap.server", server);
      }
      String user = aWritableModel.getUserDefinedAttribute("imap.user");
      if (user == null) {
        user =
            JOptionPane.showInputDialog(
                "imap-user: (can be changed later in the root-account´s properties.)");
        aWritableModel.setUserDefinedAttribute("imap.user", user);
      }
      String passwd = JOptionPane.showInputDialog("imap-password:"******"mail folder opened");

      Message[] messages = folder.getMessages();
      for (Message message : messages) {
        try {
          if (importMessage(message, aCurrentAccount, aWritableModel)) {
            message.setFlag(Flag.SEEN, true);
            folder.copyMessages(new Message[] {message}, doneFolder);
            message.setFlag(Flags.Flag.DELETED, true);
          }
        } catch (Exception e) {
          LOG.log(Level.SEVERE, "Cannot import email" + message.getSubject(), e);
        }
      }
    } catch (Exception e) {
      LOG.log(Level.SEVERE, "Cannot scan mail-folder", e);
    }
    return null;
  }
Exemplo n.º 2
0
  /**
   * @param aWritableModel
   * @param store
   * @return
   * @throws MessagingException
   * @throws JAXBException
   */
  private Folder getInputFolder(final GnucashWritableFile aWritableModel, Store store)
      throws MessagingException, JAXBException {
    String folderName = aWritableModel.getUserDefinedAttribute("imap.folder");
    Folder folder = null;
    if (folderName != null) {
      folder = store.getFolder(folderName);
    }
    while (folder == null || !folder.exists()) {
      final JDialog selectFolderDialog = new JDialog((JFrame) null, "Select mail folder");
      selectFolderDialog.getContentPane().setLayout(new BorderLayout());
      final JList folderListBox = new JList(new Vector<String>(getFolders(store)));
      JButton okButton = new JButton("OK");
      okButton.addActionListener(
          new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent aE) {
              if (folderListBox.getSelectedIndices() != null) {
                if (folderListBox.getSelectedIndices().length == 1) {
                  selectFolderDialog.setVisible(false);
                }
              }
            }
          });
      selectFolderDialog.getContentPane().add(new JScrollPane(folderListBox), BorderLayout.CENTER);
      selectFolderDialog.getContentPane().add(okButton, BorderLayout.SOUTH);
      selectFolderDialog.setModal(true);
      selectFolderDialog.pack();
      selectFolderDialog.setVisible(true);
      folderName = folderListBox.getSelectedValue().toString();
      aWritableModel.setUserDefinedAttribute("imap.folder", folderName);
      folder = store.getFolder(folderName);
    }
    return folder;
  }