| 1 22 23 package gnu.mail.providers.nntp; 24 25 import java.io.File ; 26 import java.io.IOException ; 27 import java.lang.reflect.Constructor ; 28 import javax.mail.AuthenticationFailedException ; 29 import javax.mail.Flags ; 30 import javax.mail.Folder ; 31 import javax.mail.MessagingException ; 32 import javax.mail.Session ; 33 import javax.mail.Store ; 34 import javax.mail.URLName ; 35 36 import gnu.inet.nntp.FileNewsrc; 37 import gnu.inet.nntp.Newsrc; 38 import gnu.inet.nntp.NNTPConnection; 39 40 48 public class NNTPStore extends Store  49 { 50 51 NNTPConnection connection; 52 Newsrc newsrc; 53 Folder root; 54 55 58 Flags permanentFlags; 59 60 65 public NNTPStore(Session session, URLName url) 66 { 67 super(session, url); 68 69 permanentFlags = new Flags (); 71 permanentFlags.add(Flags.Flag.RECENT); 72 permanentFlags.add(Flags.Flag.SEEN); 73 74 String tn = session.getProperty("nntp.newsrc"); 76 if (tn!=null) 77 { 78 Session.log("ERROR: nntp: unable to instantiate newsrc"); 80 } 81 else 82 { 83 StringBuffer buffer = new StringBuffer (".newsrc"); 85 if (url!=null) 86 { 87 buffer.append('-'); 88 buffer.append(url.getHost()); 89 } 90 String filename = buffer.toString(); 91 String home = System.getProperty("user.home"); 92 File file = new File (home, filename); 93 newsrc = new FileNewsrc(file, session.getDebug()); 94 } 95 } 96 97 100 protected boolean protocolConnect(String host, int port, String username, 101 String password) 102 throws MessagingException  103 { 104 try 105 { 106 if (port<0) 107 port = NNTPConnection.DEFAULT_PORT; 108 connection = new NNTPConnection(host, port, username, password, 109 debug); 110 if (username!=null && password!=null) 111 { 112 return connection.authinfo(username, password); 115 } 116 else 117 return true; 118 } 119 catch (IOException e) 120 { 121 throw new MessagingException (e.getMessage(), e); 122 } 123 catch (SecurityException e) 124 { 125 if (username!=null && password!=null) 126 throw new AuthenticationFailedException (e.getMessage()); 127 else 128 return false; 129 } 130 } 131 132 135 public void close() 136 throws MessagingException  137 { 138 try 139 { 140 newsrc.close(); 141 synchronized (connection) 142 { 143 connection.quit(); 144 } 145 } 146 catch (IOException e) 147 { 148 throw new MessagingException (e.getMessage(), e); 149 } 150 super.close(); 151 } 152 153 157 public Folder getDefaultFolder() 158 throws MessagingException  159 { 160 if (root==null) 161 root = new NNTPRootFolder(this); 162 return root; 163 } 164 165 168 public Folder getFolder(String name) 169 throws MessagingException  170 { 171 return getDefaultFolder().getFolder(name); 172 } 173 174 178 public Folder getFolder(URLName url) 179 throws MessagingException  180 { 181 return getDefaultFolder().getFolder(url.getFile()); 182 } 183 184 189 boolean isListAll() 190 { 191 String listAll = session.getProperty("mail.nntp.listAll"); 192 return (listAll!=null && "true".equals(listAll)); 193 } 194 195 } 196 | Popular Tags |