List of usage examples for javax.mail URLName getProtocol
public String getProtocol()
From source file:com.adaptris.core.mail.MailHelper.java
static final URLName createURLName(String urlString, String username, String password) throws PasswordException { URLName url = new URLName(urlString); String realPassword = url.getPassword(); String realUser = url.getUsername(); if (realUser == null && !isEmpty(username)) { realUser = username;//w ww . j a va2 s. com } if (url.getPassword() == null && password != null) { realPassword = Password.decode(password); } return new URLName(url.getProtocol(), url.getHost(), url.getPort(), url.getFile(), realUser, realPassword); }
From source file:com.adaptris.util.TestURLName.java
public void testUrl() throws Exception { URLName url = new URLName(testUrl); assertEquals(protocol, url.getProtocol()); assertEquals(username, url.getUsername()); assertEquals(password, url.getPassword()); assertEquals(host, url.getHost());/*w w w . j a va 2 s . co m*/ assertEquals(testUrl, url.toString()); }
From source file:com.adaptris.mail.MailReceiverCase.java
protected static final URLName createURLName(String urlString, String uname, String pw) throws PasswordException { URLName url = new URLName(urlString); String password = url.getPassword(); String username = url.getUsername(); if (username == null && !isEmpty(uname)) { username = uname;// w w w . j a v a 2 s. c o m } if (url.getPassword() == null && pw != null) { password = Password.decode(pw); } return new URLName(url.getProtocol(), url.getHost(), url.getPort(), url.getFile(), username, password); }
From source file:com.adaptris.mail.Pop3sReceiverFactory.java
@Override public MailReceiver createClient(URLName url) throws MailException { if (!SUPPORTED.contains(url.getProtocol().toLowerCase())) { throw new MailException(url.getProtocol() + " is not supported by this factory"); }// w w w . j a va 2 s . com return new ApachePOP3S(url, this, implicitTLS()); }
From source file:com.adaptris.mail.Pop3ReceiverFactory.java
@Override public MailReceiver createClient(URLName url) throws MailException { if (!SUPPORTED.contains(url.getProtocol().toLowerCase())) { throw new MailException(url.getProtocol() + " is not supported by this factory"); }/*from w w w .j a v a2s . co m*/ return new ApachePOP3(url, this); }
From source file:StoreTreeNode.java
/** * We override toString() so we can display the store URLName * without the password.// w w w .j a va 2 s . c o m */ public String toString() { if (display == null) { URLName url = store.getURLName(); if (url == null) { display = store.toString(); } else { // don't show the password URLName too = new URLName(url.getProtocol(), url.getHost(), url.getPort(), url.getFile(), url.getUsername(), null); display = too.toString(); } } return display; }
From source file:net.wastl.webmail.server.WebMailSession.java
/** * Refresh Information about folders.// w w w. j a v a 2 s . c om * Tries to connect folders that are not yet connected. * * @doCount display message counts for user */ public void refreshFolderInformation(boolean subscribed_only, boolean doCount) { /* Right now, doCount corresponds exactly to subscribed_only. * When we add a user preference setting or one-time action, * to present messages from all folders, we will have * subscribed_only false and doCount true. */ //log.fatal("Invoking refreshFolderInformation(boolean, boolean)", //new Throwable("Thread Dump")); FOR DEBUGGING setEnv(); if (folders == null) folders = new Hashtable<String, Folder>(); Folder rootFolder = null; String cur_mh_id = ""; Enumeration mailhosts = user.mailHosts(); int max_depth = 0; int folderType; while (mailhosts.hasMoreElements()) { cur_mh_id = (String) mailhosts.nextElement(); MailHostData mhd = user.getMailHost(cur_mh_id); URLName url = new URLName(mhd.getHostURL()); Element mailhost = model.createMailhost(mhd.getName(), mhd.getID(), url.toString()); int depth = 0; try { rootFolder = getRootFolder(cur_mh_id); try { rootFolder.setSubscribed(true); } catch (MessagingException ex) { // Only IMAP supports subscription log.warn("Folder.setSubscribed failed. " + "Probably a non-supporting mail service: " + ex); } } catch (MessagingException ex) { mailhost.setAttribute("error", ex.getMessage()); log.warn("Failed to connect and get Root folder from (" + url + ')', ex); return; } try { depth = getFolderTree(rootFolder.getFolder("INBOX"), mailhost, subscribed_only, doCount); log.debug("Loaded INBOX folders below Root to a depth of " + depth); String extraFolderPath = ((imapBasedir == null) ? "~" : imapBasedir) + mhd.getLogin(); //String extraFolderPath = "/home/" + mhd.getLogin(); Folder nonInboxBase = rootFolder.getFolder(extraFolderPath); log.debug("Trying extra base dir " + nonInboxBase.getFullName()); if (nonInboxBase.exists()) { folderType = nonInboxBase.getType(); if ((folderType & Folder.HOLDS_MESSAGES) != 0) { // Can only Subscribe to Folders which may hold Msgs. nonInboxBase.setSubscribed(true); if (!nonInboxBase.isSubscribed()) log.error("A bug in JavaMail or in the server is " + "preventing subscription to '" + nonInboxBase.getFullName() + "' on '" + url + "'. Folders will not be visible."); } int extraDepth = extraDepth = getFolderTree(nonInboxBase, mailhost, subscribed_only, doCount); if (extraDepth > depth) depth = extraDepth; log.debug("Loaded additional folders from below " + nonInboxBase.getFullName() + " with max depth of " + extraDepth); } } catch (Exception ex) { if (!url.getProtocol().startsWith("pop")) mailhost.setAttribute("error", ex.getMessage()); log.warn("Failed to fetch child folders from (" + url + ')', ex); } if (depth > max_depth) max_depth = depth; model.addMailhost(mailhost); } model.setStateVar("max folder depth", (1 + max_depth) + ""); }
From source file:net.wastl.webmail.server.WebMailSession.java
/** Connect to mailhost "name"//w ww . j a va 2 s . c o m */ public Folder connect(String name) throws MessagingException { MailHostData m = user.getMailHost(name); URLName url = new URLName(m.getHostURL()); Store st = connectStore(url.getHost(), url.getProtocol(), m.getLogin(), m.getPassword()); Folder f = st.getDefaultFolder(); connections.put(name, f); log.info("Mail: Default folder '" + f.getFullName() + "' retrieved from store " + st + '.'); return f; }
From source file:org.springframework.integration.mail.config.MailReceiverFactoryBean.java
private void verifyProtocol() { if (StringUtils.hasText(this.storeUri)) { URLName urlName = new URLName(this.storeUri); if (this.protocol == null) { this.protocol = urlName.getProtocol(); } else {//from w w w . j av a 2s . c o m Assert.isTrue(this.protocol.equals(urlName.getProtocol()), "The provided 'protocol' does not match that in the 'storeUri'."); } } else { Assert.hasText(this.protocol, "Either the 'storeUri' or 'protocol' is required."); } Assert.hasText(this.protocol, "Unable to resolve protocol."); }
From source file:org.springframework.integration.mail.MailTransportUtils.java
/** * Returns a string representation of the given {@link URLName}, where the * password has been protected.//from w w w . j a v a2 s . c om */ public static String toPasswordProtectedString(URLName name) { String protocol = name.getProtocol(); String username = name.getUsername(); String password = name.getPassword(); String host = name.getHost(); int port = name.getPort(); String file = name.getFile(); String ref = name.getRef(); StringBuffer tempURL = new StringBuffer(); if (protocol != null) { tempURL.append(protocol).append(':'); } if (StringUtils.hasLength(username) || StringUtils.hasLength(host)) { tempURL.append("//"); if (StringUtils.hasLength(username)) { tempURL.append(username); if (StringUtils.hasLength(password)) { tempURL.append(":*****"); } tempURL.append("@"); } if (StringUtils.hasLength(host)) { tempURL.append(host); } if (port != -1) { tempURL.append(':').append(Integer.toString(port)); } if (StringUtils.hasLength(file)) { tempURL.append('/'); } } if (StringUtils.hasLength(file)) { tempURL.append(file); } if (StringUtils.hasLength(ref)) { tempURL.append('#').append(ref); } return tempURL.toString(); }