manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1739381 - in /manifoldcf/trunk: ./ connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/ connectors/email/connector/src/main/resources/org/apache/manifoldcf/crawler/notifications/email/
Date Fri, 15 Apr 2016 23:48:01 GMT
Author: kwright
Date: Fri Apr 15 23:48:00 2016
New Revision: 1739381

URL: http://svn.apache.org/viewvc?rev=1739381&view=rev
Log:
Fix for CONNECTORS-1296: Revamp email notification connector.

Modified:
    manifoldcf/trunk/CHANGES.txt
    manifoldcf/trunk/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailConnector.java
    manifoldcf/trunk/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailSession.java
    manifoldcf/trunk/connectors/email/connector/src/main/resources/org/apache/manifoldcf/crawler/notifications/email/ConfigurationView.html
    manifoldcf/trunk/connectors/email/connector/src/main/resources/org/apache/manifoldcf/crawler/notifications/email/Configuration_Server.html

Modified: manifoldcf/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/CHANGES.txt?rev=1739381&r1=1739380&r2=1739381&view=diff
==============================================================================
--- manifoldcf/trunk/CHANGES.txt (original)
+++ manifoldcf/trunk/CHANGES.txt Fri Apr 15 23:48:00 2016
@@ -3,6 +3,10 @@ $Id$
 
 ======================= 2.4-dev =====================
 
+CONNECTORS-1296: Revamp email notification connector to do
+SMTP and be more configurable.
+(Markus Schuch, Karl Wright)
+
 CONNECTORS-1295: JCIFS connector ignoring max file length value
 sometimes.
 (Konstantin Avdeev, Karl Wright)

Modified: manifoldcf/trunk/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailConnector.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailConnector.java?rev=1739381&r1=1739380&r2=1739381&view=diff
==============================================================================
--- manifoldcf/trunk/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailConnector.java
(original)
+++ manifoldcf/trunk/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailConnector.java
Fri Apr 15 23:48:00 2016
@@ -48,21 +48,11 @@ public class EmailConnector extends org.
   protected String portString = null;
   protected String username = null;
   protected String password = null;
-  protected String protocol = null;
   protected Properties properties = null;
   
   // Local session handle
   protected EmailSession session = null;
 
-  private static Map<String,String> providerMap;
-  static
-  {
-    providerMap = new HashMap<String,String>();
-    providerMap.put(EmailConfig.PROTOCOL_POP3, EmailConfig.PROTOCOL_POP3_PROVIDER);
-    providerMap.put(EmailConfig.PROTOCOL_POP3S, EmailConfig.PROTOCOL_POP3S_PROVIDER);
-    providerMap.put(EmailConfig.PROTOCOL_IMAP, EmailConfig.PROTOCOL_IMAP_PROVIDER);
-    providerMap.put(EmailConfig.PROTOCOL_IMAPS, EmailConfig.PROTOCOL_IMAPS_PROVIDER);
-  }
   //////////////////////////////////Start of Basic Connector Methods/////////////////////////
 
   /**
@@ -76,7 +66,6 @@ public class EmailConnector extends org.
     super.connect(configParameters);
     this.server = configParameters.getParameter(EmailConfig.SERVER_PARAM);
     this.portString = configParameters.getParameter(EmailConfig.PORT_PARAM);
-    this.protocol = configParameters.getParameter(EmailConfig.PROTOCOL_PARAM);
     this.username = configParameters.getParameter(EmailConfig.USERNAME_PARAM);
     this.password = configParameters.getObfuscatedParameter(EmailConfig.PASSWORD_PARAM);
     this.properties = new Properties();
@@ -101,7 +90,6 @@ public class EmailConnector extends org.
     throws ManifoldCFException {
     this.server = null;
     this.portString = null;
-    this.protocol = null;
     this.username = null;
     this.password = null;
     this.properties = null;
@@ -164,8 +152,6 @@ public class EmailConnector extends org.
         throw new ManifoldCFException("Missing server parameter");
       if (properties == null)
         throw new ManifoldCFException("Missing server properties");
-      if (protocol == null)
-        throw new ManifoldCFException("Missing protocol parameter");
       
       // Create a session.
       int port;
@@ -184,8 +170,7 @@ public class EmailConnector extends org.
         port = -1;
 
       try {
-        ConnectThread connectThread = new ConnectThread(server, port, username, password,
-          providerMap.get(protocol), properties);
+        ConnectThread connectThread = new ConnectThread(server, port, username, password,
properties);
         connectThread.start();
         session = connectThread.finishUp();
       } catch (InterruptedException e) {
@@ -378,7 +363,6 @@ public class EmailConnector extends org.
     int i = 0;
     String username = parameters.getParameter(EmailConfig.USERNAME_PARAM);
     String password = parameters.getObfuscatedParameter(EmailConfig.PASSWORD_PARAM);
-    String protocol = parameters.getParameter(EmailConfig.PROTOCOL_PARAM);
     String server = parameters.getParameter(EmailConfig.SERVER_PARAM);
     String port = parameters.getParameter(EmailConfig.PORT_PARAM);
     List<Map<String, String>> list = new ArrayList<Map<String, String>>();
@@ -401,8 +385,6 @@ public class EmailConnector extends org.
       password = StringUtils.EMPTY;
     else
       password = mapper.mapPasswordToKey(password);
-    if (protocol == null)
-      protocol = EmailConfig.PROTOCOL_DEFAULT_VALUE;
     if (server == null)
       server = StringUtils.EMPTY;
     if (port == null)
@@ -410,7 +392,6 @@ public class EmailConnector extends org.
 
     paramMap.put("USERNAME", username);
     paramMap.put("PASSWORD", password);
-    paramMap.put("PROTOCOL", protocol);
     paramMap.put("SERVER", server);
     paramMap.put("PORT", port);
     paramMap.put("PROPERTIES", list);
@@ -443,10 +424,6 @@ public class EmailConnector extends org.
     if (password != null)
       parameters.setObfuscatedParameter(EmailConfig.PASSWORD_PARAM, variableContext.mapKeyToPassword(password));
 
-    String protocol = variableContext.getParameter("protocol");
-    if (protocol != null)
-      parameters.setParameter(EmailConfig.PROTOCOL_PARAM, protocol);
-
     String server = variableContext.getParameter("server");
     if (server != null)
       parameters.setParameter(EmailConfig.SERVER_PARAM, server);
@@ -800,20 +777,18 @@ public class EmailConnector extends org.
     protected final int port;
     protected final String username;
     protected final String password;
-    protected final String protocol;
     protected final Properties properties;
     
     // Local session handle
     protected EmailSession session = null;
     protected Throwable exception = null;
     
-    public ConnectThread(String server, int port, String username, String password, String
protocol, Properties properties)
+    public ConnectThread(String server, int port, String username, String password, Properties
properties)
     {
       this.server = server;
       this.port = port;
       this.username = username;
       this.password = password;
-      this.protocol = protocol;
       this.properties = properties;
       setDaemon(true);
     }
@@ -822,7 +797,7 @@ public class EmailConnector extends org.
     {
       try
       {
-        session = new EmailSession(server, port, username, password, protocol, properties);
+        session = new EmailSession(server, port, username, password, properties);
       }
       catch (Throwable e)
       {

Modified: manifoldcf/trunk/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailSession.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailSession.java?rev=1739381&r1=1739380&r2=1739381&view=diff
==============================================================================
--- manifoldcf/trunk/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailSession.java
(original)
+++ manifoldcf/trunk/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailSession.java
Fri Apr 15 23:48:00 2016
@@ -33,42 +33,59 @@ public class EmailSession
   protected final int port;
   protected final String username;
   protected final String password;
-  protected final String protocol;
   protected final Properties properties;
 
   private Session session = null;
-  private Store store = null;
 
   /** Create a session */
-  public EmailSession(String server, int port, String username, String password,
-    String protocol, Properties properties)
+  public EmailSession(final String server, final int port, final String username, final String
password,
+    Properties properties)
     throws MessagingException
   {
     this.server = server;
     this.port = port;
     this.username = username;
     this.password = password;
-    this.protocol = protocol;
     this.properties = properties;
+
+    properties.put("mail.smtp.host", server);
+    properties.put("mail.smtp.port", new Integer(port).toString());
+
+    if (properties.get("mail.smtp.connectiontimeout") == null) {
+      properties.put("mail.smtp.connectiontimeout", new Integer(60000));
+    }
+    if (properties.get("mail.smtp.timeout") == null) {
+      properties.put("mail.smtp.timeout", new Integer(60000));
+    }
+    if (properties.get("mail.smtp.writetimeout") == null) {
+      properties.put("mail.smtp.writetimeout", new Integer(60000));
+    }
     
-    // Now, try to connect
-    Session thisSession = Session.getDefaultInstance(properties, null);
-    Store thisStore = thisSession.getStore(protocol);
-    thisStore.connect(server, port, username, password);
+    if (username != null && username.length() > 0) {
+      properties.put("mail.smtp.auth", "true");
+    }
+    
+    if (properties.get("mail.smtp.starttls.enable") == null) {
+      properties.put("mail.smtp.starttls.enable", "true");
+      //properties.put("mail.smtp.ssl.trust", true);
+    }
 
+    
+    // Now, try to connect
+    final Session thisSession = Session.getInstance(properties,
+      new javax.mail.Authenticator() {
+        protected PasswordAuthentication getPasswordAuthentication() {
+          return new PasswordAuthentication(username, password);
+        }
+      });
+  
     session = thisSession;
-    store = thisStore;
   }
   
   public void checkConnection()
     throws MessagingException
   {
-    if (store != null)
-    {
-      if (store.getDefaultFolder() == null) {
-        throw new MessagingException("Error checking the connection: No default folder.");
-      }
-    }
+    // Need something here...
   }
 
   public void send(List<String> to, String from, String subject, String body)
@@ -98,11 +115,6 @@ public class EmailSession
   public void close()
     throws MessagingException
   {
-    if (store != null)
-    {
-      store.close();
-      store = null;
-    }
     session = null;
   }
 }
\ No newline at end of file

Modified: manifoldcf/trunk/connectors/email/connector/src/main/resources/org/apache/manifoldcf/crawler/notifications/email/ConfigurationView.html
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/email/connector/src/main/resources/org/apache/manifoldcf/crawler/notifications/email/ConfigurationView.html?rev=1739381&r1=1739380&r2=1739381&view=diff
==============================================================================
--- manifoldcf/trunk/connectors/email/connector/src/main/resources/org/apache/manifoldcf/crawler/notifications/email/ConfigurationView.html
(original)
+++ manifoldcf/trunk/connectors/email/connector/src/main/resources/org/apache/manifoldcf/crawler/notifications/email/ConfigurationView.html
Fri Apr 15 23:48:00 2016
@@ -19,15 +19,6 @@ limitations under the License.
   
   <tr>
     <td class="description">
-      <nobr>$Encoder.bodyEscape($ResourceBundle.getString('EmailConnector.ProtocolColon'))</nobr>
-    </td>
-    <td class="value">
-      <nobr>$Encoder.bodyEscape($PROTOCOL)</nobr>
-    </td>
-  </tr>
-  
-  <tr>
-    <td class="description">
       <nobr>$Encoder.bodyEscape($ResourceBundle.getString('EmailConnector.HostNameColon'))</nobr>
     </td>
     <td class="value">

Modified: manifoldcf/trunk/connectors/email/connector/src/main/resources/org/apache/manifoldcf/crawler/notifications/email/Configuration_Server.html
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/email/connector/src/main/resources/org/apache/manifoldcf/crawler/notifications/email/Configuration_Server.html?rev=1739381&r1=1739380&r2=1739381&view=diff
==============================================================================
--- manifoldcf/trunk/connectors/email/connector/src/main/resources/org/apache/manifoldcf/crawler/notifications/email/Configuration_Server.html
(original)
+++ manifoldcf/trunk/connectors/email/connector/src/main/resources/org/apache/manifoldcf/crawler/notifications/email/Configuration_Server.html
Fri Apr 15 23:48:00 2016
@@ -21,36 +21,6 @@ limitations under the License.
   <tr><td class="separator" colspan="2"><hr/></td></tr>
   <tr>
     <td class="description">
-      <nobr>$Encoder.bodyEscape($ResourceBundle.getString('EmailConnector.ProtocolColon'))</nobr>
-    </td>
-    <td class="value">
-      <select id="protocol" name="protocol" size="2">
-  #if($PROTOCOL == 'IMAP')
-        <option value="IMAP" selected="selected">IMAP</option>
-  #else
-        <option value="IMAP">IMAP</option>
-  #end
-  #if($PROTOCOL == 'IMAP-SSL')
-        <option value="IMAP-SSL" selected="selected">IMAP-SSL</option>
-  #else
-        <option value="IMAP-SSL">IMAP-SSL</option>
-  #end
-  #if($PROTOCOL == 'POP3')
-        <option value="POP3" selected="selected">POP3</option>
-  #else
-        <option value="POP3">POP3</option>
-  #end
-  #if($PROTOCOL == 'POP3-SSL')
-        <option value="POP3-SSL" selected="selected">POP3-SSL</option>
-  #else
-        <option value="POP3-SSL">POP3-SSL</option>
-  #end
-      </select>
-    </td>
-  </tr>
-  
-  <tr>
-    <td class="description">
       <nobr>$Encoder.bodyEscape($ResourceBundle.getString('EmailConnector.HostNameColon'))</nobr>
     </td>
     <td class="value">
@@ -171,7 +141,6 @@ limitations under the License.
 
 <input type="hidden" name="username" value="$Encoder.attributeEscape($USERNAME)"/>
 <input type="hidden" name="password" value="$Encoder.attributeEscape($PASSWORD)"/>
-<input type="hidden" name="protocol" value="$Encoder.attributeEscape($PROTOCOL)"/>
 <input type="hidden" name="server" value="$Encoder.attributeEscape($SERVER)"/>
 <input type="hidden" name="port" value="$Encoder.attributeEscape($PORT)"/>
 



Mime
View raw message