KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > MailEngine > transfer > TransferFunctions


1 package SnowMailClient.MailEngine.transfer;
2
3 import SnowMailClient.model.folders.*;
4 import SnowMailClient.model.accounts.*;
5 import SnowMailClient.model.*;
6 import snow.utils.gui.*;
7 import snow.concurrent.*;
8
9 import SnowMailClient.MailEngine.*;
10 import SnowMailClient.SnowMailClientApp;
11 import SnowMailClient.view.folders.*;
12 import SnowMailClient.view.FolderView;
13 import SnowMailClient.Language.Language;
14 import SnowMailClient.gnupg.*;
15 import SnowMailClient.gnupg.model.GnuPGKeyID;
16
17 import java.awt.*;
18 import java.util.*;
19 import java.awt.event.*;
20 import javax.swing.*;
21 import javax.swing.event.*;
22 import javax.swing.tree.*;
23
24 public class TransferFunctions
25 {
26   private TransferFunctions()
27   {
28   }
29
30   /** send the mail and put it in the sent folder (if succeded)
31   */

32   public static void sendMail(final MailMessage mess, Interrupter interrupter, Counter counter) throws Exception JavaDoc
33   {
34     // just a little check
35
if( SwingUtilities.isEventDispatchThread())
36     {
37        new Throwable JavaDoc("Must be called from another thread than EDT").printStackTrace();
38     }
39     SnowMailClientApp.getInstance().saveAllMails(false);
40
41     SecureSmtpConnection ssmtp = null;
42
43     try
44     {
45        String JavaDoc fromMailAddress = mess.getFromAddress().getMailAddress();
46        MailAccount account = SnowMailClientApp.getInstance().getAccounts().getMailAccount(fromMailAddress);
47        if(account==null)
48        {
49          throw new Exception JavaDoc(Language.translate("No mail account found to send message, use a valid from address"));
50        }
51
52        if(mess.getMustBeSigned())
53        {
54          try
55          {
56            MessageActions.prepare_Signing_Mail(mess, interrupter);
57          }
58          catch(Exception JavaDoc e)
59          {
60            throw e;
61          }
62        }
63
64        if(mess.getMustBeEncrypted())
65        {
66          try
67          {
68            MessageActions.prepareEncryptMail(mess);
69          }
70          catch(Exception JavaDoc e)
71          {
72            throw e;
73          }
74        }
75
76        ssmtp = account.getSMTPConnection();
77
78        //progressDialog.setMessageProgressActive(mess.getSize());
79
ssmtp.sendMessage( mess, interrupter, counter );
80
81        // no more bold in views, no more editable
82
mess.setIsNoMoreNew();
83        //mess.setHasBeenSent(true);
84
mess.setEditable(false);
85
86
87        EventQueue.invokeLater(new Runnable JavaDoc()
88        {
89          public void run()
90          {
91            try
92            {
93               SnowMailClientApp.getInstance().getFoldersModel().getSentFolder().getMailFolder().addMessage(mess);
94               // remove after successful add.
95
SnowMailClientApp.getInstance().getFoldersModel().getOutboxFolder().getMailFolder().removeMessage(mess);
96            }
97            catch(Exception JavaDoc e)
98            {
99               JOptionPane.showMessageDialog(SnowMailClientApp.getInstance().getContentPane(),
100                 ""+e.getMessage(),
101                 Language.translate("Cannot move mail message from outbox to sent folder."
102                 +"\nHowever, the message was succesfully sent."),
103                 JOptionPane.ERROR_MESSAGE);
104               e.printStackTrace();
105            }
106          }
107        });
108
109        // add the address to the book
110
for(Address a : mess.getToAddresses())
111        {
112          SnowMailClientApp.getInstance().getAddressBook().incrementMailsSendedTo( a );
113        }
114
115     }
116     catch(Exception JavaDoc e)
117     {
118       throw e;
119     }
120     finally
121     {
122       if(ssmtp!=null)
123       {
124         try
125         {
126           ssmtp.terminateSession();
127         }
128         catch(Exception JavaDoc bof) {}
129       }
130     }
131   }
132
133
134
135
136 } // TransferFunctions
Popular Tags