openmeetings-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From solo...@apache.org
Subject svn commit: r1451518 - in /openmeetings/trunk/singlewebapp: WebContent/WEB-INF/ src/org/apache/openmeetings/data/basic/dao/ src/org/apache/openmeetings/data/conference/ src/org/apache/openmeetings/data/user/ src/org/apache/openmeetings/persistence/bean...
Date Fri, 01 Mar 2013 08:13:19 GMT
Author: solomax
Date: Fri Mar  1 08:13:18 2013
New Revision: 1451518

URL: http://svn.apache.org/r1451518
Log:
[OPENMEETINGS-327] Restart Save Mail-Queue is implemented

Added:
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/basic/dao/MailMessageDao.java
Removed:
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/utils/mail/MailThread.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/utils/mail/MailiCalThread.java
Modified:
    openmeetings/trunk/singlewebapp/WebContent/WEB-INF/openmeetings-applicationContext.xml
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/conference/FeedbackManager.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/conference/InvitationManager.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/user/EmailManager.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/user/UserManager.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/persistence/beans/basic/MailMessage.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/remote/UserService.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/remote/red5/ScopeApplicationAdapter.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/utils/mail/MailHandler.java

Modified: openmeetings/trunk/singlewebapp/WebContent/WEB-INF/openmeetings-applicationContext.xml
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/WebContent/WEB-INF/openmeetings-applicationContext.xml?rev=1451518&r1=1451517&r2=1451518&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/WebContent/WEB-INF/openmeetings-applicationContext.xml
(original)
+++ openmeetings/trunk/singlewebapp/WebContent/WEB-INF/openmeetings-applicationContext.xml
Fri Mar  1 08:13:18 2013
@@ -171,12 +171,57 @@
 		</property>
 	</bean>
 
+	<!-- Mail related jobs -->
+	<bean id="mailHandler" class="org.apache.openmeetings.utils.mail.MailHandler" />
+	<bean id="resetSendingMailStatus" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
+		<property name="targetObject">
+			<ref bean="mailHandler" />
+		</property>
+		<property name="targetMethod">
+			<value>resetSendingStatus</value>
+		</property>
+		<property name="concurrent" value="false" />
+	</bean>
+	<bean id="triggerResetSendingMailStatus" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
+		<property name="jobDetail">
+			<ref bean="resetSendingMailStatus" />
+		</property>
+		<property name="startDelay">
+			<value>60000</value> <!-- 1 minute -->
+		</property>
+		<property name="repeatInterval">
+			<value>900000</value> <!-- 15 minutes -->
+		</property>
+	</bean>
+	<bean id="sendMails" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
+		<property name="targetObject">
+			<ref bean="mailHandler" />
+		</property>
+		<property name="targetMethod">
+			<value>sendMails</value>
+		</property>
+		<property name="concurrent" value="false" />
+	</bean>
+	<bean id="triggerSendMails" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
+		<property name="jobDetail">
+			<ref bean="sendMails" />
+		</property>
+		<property name="startDelay">
+			<value>180000</value> <!-- 3 minute -->
+		</property>
+		<property name="repeatInterval">
+			<value>180000</value> <!-- 3 minutes -->
+		</property>
+	</bean>
+	
 	<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
 		<property name="triggers">
 			<list>
 				<ref local="triggerSessionClear" />
 				<ref local="triggerMeetingReminder" />
 				<ref local="triggerTestSetupCleanup" />
+				<ref local="triggerResetSendingMailStatus" />
+				<ref local="triggerSendMails" />
 			</list>
 		</property>
 	</bean>
@@ -234,14 +279,13 @@
 	<bean id="serverDao" class="org.apache.openmeetings.data.basic.dao.ServerDao" />
 	<bean id="chatDao" class="org.apache.openmeetings.data.chat.ChatDao" />
 	<bean id="clientDao" class="org.apache.openmeetings.data.conference.dao.ClientDao" />
-
+	<bean id="mailMessageDao" class="org.apache.openmeetings.data.basic.dao.MailMessageDao"
/>
 
 	<!-- No Interface -->
 	<bean id="manageCryptStyle" class="org.apache.openmeetings.utils.crypt.ManageCryptStyle"
/>
 	<bean id="generateImage" class="org.apache.openmeetings.documents.GenerateImage" />
 	<bean id="generateThumbs" class="org.apache.openmeetings.documents.GenerateThumbs" />
 	<bean id="generatePDF" class="org.apache.openmeetings.documents.GeneratePDF" />
-	<bean id="mailHandler" class="org.apache.openmeetings.utils.mail.MailHandler" />
 	<bean id="smsHandler" class="org.apache.openmeetings.utils.sms.SMSHandler" />
 	<bean id="feedbackManagement" class="org.apache.openmeetings.data.conference.FeedbackManager"
/>
 	<bean id="importInitvalues" class="org.apache.openmeetings.installation.ImportInitvalues"
/>
@@ -271,9 +315,6 @@
 		<property name="queueCapacity" value="25" />
 	</bean>
 
-	<bean id="mailThread" class="org.apache.openmeetings.utils.mail.MailThread" />
-	<bean id="mailiCalThread" class="org.apache.openmeetings.utils.mail.MailiCalThread" />
-
 	<!-- Axis2 Service Proxy's -->
 	<bean id="userWebService" class="org.apache.openmeetings.axis.services.UserWebService"
/>
 	<bean id="roomWebService" class="org.apache.openmeetings.axis.services.RoomWebService"
/>

Added: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/basic/dao/MailMessageDao.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/basic/dao/MailMessageDao.java?rev=1451518&view=auto
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/basic/dao/MailMessageDao.java
(added)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/basic/dao/MailMessageDao.java
Fri Mar  1 08:13:18 2013
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") +  you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.data.basic.dao;
+
+import java.util.Calendar;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.apache.openmeetings.data.IDataProviderDao;
+import org.apache.openmeetings.persistence.beans.basic.MailMessage;
+import org.apache.openmeetings.persistence.beans.basic.MailMessage.Status;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class MailMessageDao  implements IDataProviderDao<MailMessage> {
+	@PersistenceContext
+	private EntityManager em;
+	
+	public MailMessage get(long id) {
+		return em.createNamedQuery("getMailMessageById", MailMessage.class).setParameter("id",
id).getSingleResult();
+	}
+
+	public List<MailMessage> get(int start, int count) {
+		return em.createNamedQuery("getMailMessages", MailMessage.class).setParameter("status",
Status.NONE)
+				.setFirstResult(start).setMaxResults(count).getResultList();
+	}
+
+	public List<MailMessage> get(String search, int start, int count, String order) {
+		return get(start, count);
+	}
+
+	public long count() {
+		return em.createNamedQuery("countMailMessages", Long.class).setParameter("status", Status.NONE)
+				.getSingleResult();
+	}
+
+	public long count(String search) {
+		return count();
+	}
+
+	public void resetSendingStatus(Calendar date) {
+		em.createQuery("UPDATE MailMessage m SET m.status = :noneStatus WHERE m.status = :sendingStatus
" +
+				"	AND m.updated < :date")
+			.setParameter("noneStatus", Status.NONE)
+			.setParameter("sendingStatus", Status.SENDING)
+			.setParameter("date", date)
+			.executeUpdate();
+	}
+	
+	public MailMessage update(MailMessage m, Long userId) {
+		if (m.getId() == null) {
+			m.setInserted(Calendar.getInstance());
+			em.persist(m);
+		} else {
+			m.setUpdated(Calendar.getInstance());
+			m =	em.merge(m);
+		}
+		return m;
+	}
+
+	public void delete(MailMessage m, Long userId) {
+		em.remove(m);
+	}
+}

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/conference/FeedbackManager.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/conference/FeedbackManager.java?rev=1451518&r1=1451517&r2=1451518&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/conference/FeedbackManager.java
(original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/conference/FeedbackManager.java
Fri Mar  1 08:13:18 2013
@@ -48,11 +48,11 @@ public class FeedbackManager {
 			String template = feedbackTemplate.getFeedBackTemplate(username,
 					email, message, default_lang_id);
 
-			return mailHandler.sendMail("openmeetings-user@googlegroups.com",
+			mailHandler.send("user@openmeetings.apache.org",
 					fieldManager.getString(499L, default_lang_id), template);
-
+			return "success";
 		} catch (Exception err) {
-			log.error("sendInvitationLink", err);
+			log.error("sendFeedback", err);
 		}
 		return null;
 	}

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/conference/InvitationManager.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/conference/InvitationManager.java?rev=1451518&r1=1451517&r2=1451518&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/conference/InvitationManager.java
(original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/conference/InvitationManager.java
Fri Mar  1 08:13:18 2013
@@ -40,6 +40,7 @@ import org.apache.openmeetings.data.cale
 import org.apache.openmeetings.data.conference.dao.RoomDao;
 import org.apache.openmeetings.data.user.UserManager;
 import org.apache.openmeetings.data.user.dao.UsersDao;
+import org.apache.openmeetings.persistence.beans.basic.MailMessage;
 import org.apache.openmeetings.persistence.beans.basic.OmTimeZone;
 import org.apache.openmeetings.persistence.beans.calendar.Appointment;
 import org.apache.openmeetings.persistence.beans.calendar.MeetingMember;
@@ -51,7 +52,6 @@ import org.apache.openmeetings.utils.cry
 import org.apache.openmeetings.utils.crypt.ManageCryptStyle;
 import org.apache.openmeetings.utils.mail.IcalHandler;
 import org.apache.openmeetings.utils.mail.MailHandler;
-import org.apache.openmeetings.utils.mail.MailiCalThread;
 import org.apache.openmeetings.utils.math.CalendarPatterns;
 import org.apache.openmeetings.utils.math.TimezoneUtil;
 import org.apache.openmeetings.utils.sms.SMSHandler;
@@ -90,8 +90,6 @@ public class InvitationManager {
 	@Autowired
 	private MailHandler mailHandler;
 	@Autowired
-	private MailiCalThread mailiCalThread;
-	@Autowired
 	private SMSHandler smsHandler;
 	@Autowired
 	private InvitationTemplate invitationTemplate;
@@ -631,8 +629,8 @@ public class InvitationManager {
 					fromUserField, message, invitation_link, language_id, dStart,
 					dEnd);
 
-			return mailHandler.sendMail(email, replyTo, subject, template);
-
+			mailHandler.send(email, replyTo, subject, template);
+			return "success";
 		} catch (Exception err) {
 			log.error("sendInvitationLink", err);
 		}
@@ -658,9 +656,14 @@ public class InvitationManager {
 			String invitation_link = baseUrl + "?invitationHash="
 					+ invitationHash;
 
-			return mailHandler.sendMail(email, subject
+			mailHandler.send(new MailMessage(
+					email
+					, null
+					, subject
 					, message + "<br/><a href='" + invitation_link + "'>"
-					+ fieldManager.getFieldByIdAndLanguage(626L, langId) + "</a>");
+							+ fieldManager.getFieldByIdAndLanguage(626L, langId) + "</a>"), true);
+			
+			return "success";
 		} catch (Exception e) {
 			log.error("sendInvitationReminderLink", e);
 		}
@@ -700,7 +703,8 @@ public class InvitationManager {
 			String cancelling_person, String subject, String message) {
 		log.debug("sendInvitationCancelmail");
 		try {
-			return mailHandler.sendMail(email, subject, message);
+			mailHandler.send(email, subject, message);
+			return "success";
 		} catch (Exception e) {
 			log.error("sendInvitationCancelmail : " + e.getMessage());
 		}
@@ -724,7 +728,8 @@ public class InvitationManager {
 			String replyTo, String subject, String message) {
 		log.debug("sendInvitationUpdateMail");
 		try {
-			return mailHandler.sendMail(email, replyTo, subject, message);
+			mailHandler.send(email, replyTo, subject, message);
+			return "success";
 		} catch (Exception e) {
 			log.error("sendInvitationUpdateMail : " + e.getMessage());
 		}
@@ -752,8 +757,7 @@ public class InvitationManager {
 		User user = userManager.getUserById(organizer_userId);
 
 		// TODO: Check time zone handling in iCal Mail
-		// OmTimeZone omTimeZone =
-		// omTimeZoneDaoImpl.getOmTimeZone(jNameTimeZone);
+		// OmTimeZone omTimeZone = omTimeZoneDaoImpl.getOmTimeZone(jNameTimeZone);
 
 		IcalHandler handler = new IcalHandler(IcalHandler.ICAL_METHOD_CANCEL);
 
@@ -777,8 +781,7 @@ public class InvitationManager {
 
 		log.debug(handler.getICalDataAsString());
 
-		mailiCalThread.doSend(email, user.getAdresses().getEmail(), subject, handler.getIcalAsByteArray(),
-				message);
+		mailHandler.send(new MailMessage(email, user.getAdresses().getEmail(), subject, message,
handler.getIcalAsByteArray()));
 
 		return null;
 	}
@@ -823,8 +826,7 @@ public class InvitationManager {
 
 		log.debug(handler.getICalDataAsString());
 
-		mailiCalThread.doSend(email, user.getAdresses().getEmail(), subject, handler.getIcalAsByteArray(),
-				message);
+		mailHandler.send(new MailMessage(email, user.getAdresses().getEmail(), subject, message,
handler.getIcalAsByteArray()));
 
 		return null;
 	}
@@ -907,12 +909,9 @@ public class InvitationManager {
 
 			log.debug(handler.getICalDataAsString());
 
-			mailiCalThread.doSend(email, replyToEmail, subject, handler.getIcalAsByteArray(),
-					template);
+			mailHandler.send(new MailMessage(email, replyToEmail, subject, template, handler.getIcalAsByteArray()));
 
 			return "success";
-			// return MailHandler.sendMail(email, subject, template);
-
 		} catch (Exception err) {
 			log.error("sendInvitionIcalLink", err);
 		}
@@ -952,8 +951,8 @@ public class InvitationManager {
 								invitation_link, default_lang_id, starttime,
 								endtime);
 
-				return mailHandler.sendMail(email, replyTo, subject, template);
-
+				mailHandler.send(email, replyTo, subject, template);
+				return "success";
 			}
 		} catch (Exception err) {
 			log.error("sendInvitationLink", err);

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/user/EmailManager.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/user/EmailManager.java?rev=1451518&r1=1451517&r2=1451518&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/user/EmailManager.java
(original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/user/EmailManager.java
Fri Mar  1 08:13:18 2013
@@ -68,7 +68,6 @@ public class EmailManager {
 	 */
 	public String sendMail(String Username, String Userpass, String EMail,
 			String link, Boolean sendEmailWithVerficationCode) {
-		String succ = "valid email";
 
 		Integer sendEmailAtRegister = configurationDao.getConfValue("sendEmailAtRegister", Integer.class,
"0");
 
@@ -76,30 +75,22 @@ public class EmailManager {
 
 			Long default_lang_id = configurationDao.getConfValue("default_lang_id", Long.class, "1");
 
+			String template = null;
 			if (sendEmailWithVerficationCode) {
-
 				String verification_url = link;
 
-				String template = registerUserTemplate
+				template = registerUserTemplate
 						.getRegisterUserWithVerificationTemplate(Username,
 								Userpass, EMail, default_lang_id,
 								verification_url);
-
-				succ = mailHandler.sendMail(EMail, fieldManager.getString(512L, default_lang_id), template);
-
 			} else {
-
-				String template = registerUserTemplate
+				template = registerUserTemplate
 						.getRegisterUserTemplate(Username, Userpass, EMail,
 								default_lang_id);
-
-				succ = mailHandler.sendMail(EMail, fieldManager.getString(512L, default_lang_id), template);
 			}
-
-			return succ;
-		} else {
-			return "success";
+			mailHandler.send(EMail, fieldManager.getString(512L, default_lang_id), template);
 		}
+		return "success";
 	}
 
 	public String addEmailCon(String EMail, int CONTACT_ID) {

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/user/UserManager.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/user/UserManager.java?rev=1451518&r1=1451517&r2=1451518&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/user/UserManager.java
(original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/user/UserManager.java
Fri Mar  1 08:13:18 2013
@@ -1298,7 +1298,7 @@ public class UserManager {
 		String template = resetPasswordTemplate.getResetPasswordTemplate(
 				reset_link, default_lang_id);
 
-		mailHandler.sendMail(email, fieldManager.getString(517L, default_lang_id), template);
+		mailHandler.send(email, fieldManager.getString(517L, default_lang_id), template);
 	}
 
 	/**

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/persistence/beans/basic/MailMessage.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/persistence/beans/basic/MailMessage.java?rev=1451518&r1=1451517&r2=1451518&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/persistence/beans/basic/MailMessage.java
(original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/persistence/beans/basic/MailMessage.java
Fri Mar  1 08:13:18 2013
@@ -18,21 +18,43 @@
  */
 package org.apache.openmeetings.persistence.beans.basic;
 
+import java.util.Calendar;
+
 import javax.persistence.Column;
 import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
+import javax.persistence.Lob;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
 import javax.persistence.Table;
 
+import org.apache.openmeetings.persistence.beans.IDataProviderEntity;
+
 @Entity
+@NamedQueries({
+	@NamedQuery(name = "getMailMessageById", query = "SELECT m FROM MailMessage m WHERE m.id
= :id")
+	, @NamedQuery(name = "getMailMessages"
+		, query = "SELECT m FROM MailMessage m WHERE m.status = :status ORDER BY m.updated, m.inserted")
+	, @NamedQuery(name = "countMailMessages", query = "SELECT COUNT(m) FROM MailMessage m WHERE
m.status = :status")
+})
 @Table(name = "email")
-public class MailMessage {
+public class MailMessage implements IDataProviderEntity {
+	public enum Status {
+		NONE
+		, SENDING
+		, DONE
+	}
+	
 	@Id
 	@GeneratedValue(strategy = GenerationType.IDENTITY)
 	@Column(name = "id")
 	private Long id;
 	
+	@Lob
 	@Column(name = "recipients")
 	private String recipients;
 	
@@ -42,12 +64,36 @@ public class MailMessage {
 	@Column(name = "subject")
 	private String subject;
 	
+	@Lob
 	@Column(name = "body")
 	private String body;
 
-	@Column(name = "processed")
-	private boolean processed;
+	@Lob
+	@Column(name = "ics")
+	private byte[] ics;
+
+	@Column(name = "status", nullable = false)
+	@Enumerated(EnumType.STRING)
+	private Status status = Status.NONE;
 
+	@Column(name = "inserted")
+	private Calendar inserted;
+	
+	@Column(name = "updated")
+	private Calendar updated;
+	
+	public MailMessage(String recipients, String replyTo, String subject, String body) {
+		this(recipients, replyTo, subject, body, null);
+	}
+	
+	public MailMessage(String recipients, String replyTo, String subject, String body, byte[]
ics) {
+		this.recipients = recipients;
+		this.replyTo = replyTo;
+		this.subject = subject;
+		this.body = body;
+		this.ics = ics;
+	}
+	
 	public Long getId() {
 		return id;
 	}
@@ -88,11 +134,35 @@ public class MailMessage {
 		this.body = body;
 	}
 
-	public boolean isProcessed() {
-		return processed;
+	public Status getStatus() {
+		return status;
+	}
+
+	public void setStatus(Status status) {
+		this.status = status;
+	}
+
+	public Calendar getInserted() {
+		return inserted;
+	}
+
+	public void setInserted(Calendar inserted) {
+		this.inserted = inserted;
+	}
+
+	public Calendar getUpdated() {
+		return updated;
+	}
+
+	public void setUpdated(Calendar updated) {
+		this.updated = updated;
+	}
+
+	public byte[] getIcs() {
+		return ics;
 	}
 
-	public void setProcessed(boolean processed) {
-		this.processed = processed;
+	public void setIcs(byte[] ics) {
+		this.ics = ics;
 	}
 }

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/remote/UserService.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/remote/UserService.java?rev=1451518&r1=1451517&r2=1451518&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/remote/UserService.java (original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/remote/UserService.java Fri
Mar  1 08:13:18 2013
@@ -716,7 +716,7 @@ public class UserService {
 								denyLinkHTML, profileLinkHTML);
 
 				if (userToAdd.getAdresses() != null) {
-					mailHandler.sendMail(userToAdd.getAdresses().getEmail(),
+					mailHandler.send(userToAdd.getAdresses().getEmail(),
 							user.getFirstname() + " " + user.getLastname()
 									+ " " + fValue1193.getValue(), template);
 				}
@@ -915,7 +915,7 @@ public class UserService {
 								false, null, false, 0L, user.getAdresses()
 										.getEmail());
 
-						mailHandler.sendMail(user.getAdresses().getEmail(),
+						mailHandler.send(user.getAdresses().getEmail(),
 								userContacts.getContact().getFirstname()
 										+ " "
 										+ userContacts.getContact()
@@ -1171,7 +1171,7 @@ public class UserService {
 								+ labelid504.getValue() + "</a><br/>";
 					}
 
-					mailHandler.sendMail(email, fValue1301.getValue() + " "
+					mailHandler.send(email, fValue1301.getValue() + " "
 							+ subject, message.replaceAll("\\<.*?>", "")
 							+ aLinkHTML + invitation_link);
 

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/remote/red5/ScopeApplicationAdapter.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/remote/red5/ScopeApplicationAdapter.java?rev=1451518&r1=1451517&r2=1451518&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/remote/red5/ScopeApplicationAdapter.java
(original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/remote/red5/ScopeApplicationAdapter.java
Fri Mar  1 08:13:18 2013
@@ -146,7 +146,7 @@ public class ScopeApplicationAdapter ext
 			for (String scopeName : scope.getScopeNames()) {
 				log.debug("scopeName :: " + scopeName);
 			}
-
+			
 			ScopeApplicationAdapter.initComplete = true;
 		    log.debug("\n" + 
 		    		"\t################################################\n" +

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/utils/mail/MailHandler.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/utils/mail/MailHandler.java?rev=1451518&r1=1451517&r2=1451518&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/utils/mail/MailHandler.java
(original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/utils/mail/MailHandler.java
Fri Mar  1 08:13:18 2013
@@ -18,10 +18,35 @@
  */
 package org.apache.openmeetings.utils.mail;
 
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Properties;
+
+import javax.activation.DataHandler;
+import javax.mail.BodyPart;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Multipart;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+import javax.mail.util.ByteArrayDataSource;
+
 import org.apache.openmeetings.OpenmeetingsVariables;
+import org.apache.openmeetings.data.basic.dao.ConfigurationDao;
+import org.apache.openmeetings.data.basic.dao.MailMessageDao;
+import org.apache.openmeetings.persistence.beans.basic.MailMessage;
+import org.apache.openmeetings.persistence.beans.basic.MailMessage.Status;
 import org.red5.logging.Red5LoggerFactory;
 import org.slf4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.task.TaskExecutor;
 
 /**
  * 
@@ -31,40 +56,171 @@ import org.springframework.beans.factory
 public class MailHandler {
 	private static final Logger log = Red5LoggerFactory.getLogger(
 			MailHandler.class, OpenmeetingsVariables.webAppRootKey);
+	private static final int MAIL_SEND_TIMEOUT = 60 * 60 * 1000; // 1 hour
 	
 	@Autowired
-	private MailThread mailThread;
+	private ConfigurationDao cfgDao;
+	@Autowired
+	private TaskExecutor taskExecutor;
+	@Autowired
+	private MailMessageDao mailMessageDao;
+
+	protected MimeMessage appendIcsBody(MimeMessage msg, MailMessage m) throws Exception {
+		log.debug("setMessageBody for iCal message");
+		// -- Create a new message --
+		Multipart multipart = new MimeMultipart();
+
+		Multipart multiBody = new MimeMultipart("alternative");
+		BodyPart html = new MimeBodyPart();
+		html.setDataHandler(new DataHandler(new ByteArrayDataSource(m.getBody(), "text/html; charset=UTF-8")));
+		multiBody.addBodyPart(html);
+
+		BodyPart iCalContent = new MimeBodyPart();
+		iCalContent.addHeader("content-class", "urn:content-classes:calendarmessage");
+		iCalContent.setDataHandler(new DataHandler(new ByteArrayDataSource(new ByteArrayInputStream(m.getIcs()),
+				"text/calendar; charset=UTF-8; method=REQUEST")));
+		multiBody.addBodyPart(iCalContent);
+		BodyPart body = new MimeBodyPart();
+		body.setContent(multiBody);
+		multipart.addBodyPart(body);
+		
+		BodyPart iCalAttachment = new MimeBodyPart();
+		iCalAttachment.setDataHandler(new DataHandler(new ByteArrayDataSource(new ByteArrayInputStream(m.getIcs()),
+				"application/ics")));
+		iCalAttachment.removeHeader("Content-Transfer-Encoding");
+		iCalAttachment.addHeader("Content-Transfer-Encoding", "base64");
+		iCalAttachment.removeHeader("Content-Type");
+		iCalAttachment.addHeader("Content-Type", "application/ics");
+		iCalAttachment.setFileName("invite.ics");
+		multipart.addBodyPart(iCalAttachment);
+
+		msg.setContent(multipart);
+		return msg;
+	}
+	
+	private MimeMessage appendBody(MimeMessage msg, MailMessage m) throws MessagingException,
IOException {
+		// -- Set the subject and body text --
+		msg.setDataHandler(new DataHandler(new ByteArrayDataSource(m.getBody(), "text/html; charset=\"utf-8\"")));
 
-	/**
-	 * send mail to address
-	 * 
-	 * @param toEmail
-	 * @param subj
-	 * @param message
-	 * @return "success" or "Error: err description"
-	 */
-	public String sendMail(String toEmail, String subj, String message) {
-		return sendMail(toEmail, null, subj, message);
-	}
-	
-	/**
-	 * send mail to address
-	 * 
-	 * @param toEmail
-	 * @param replyTo
-	 * @param subj
-	 * @param message
-	 * @return "success" or "Error: err description"
-	 */
-	public String sendMail(String toEmail, String replyTo, String subj, String message) {
-		try {
-			mailThread.doSend(toEmail, replyTo, subj, message);
-
-			return "success";
-
-		} catch (Exception ex) {
-			log.error("[sendMail] ", ex);
-			return "Error: " + ex;
+		// -- Set some other header information --
+		msg.setHeader("X-Mailer", "XML-Mail");
+		msg.setSentDate(new Date());
+		
+		return msg;
+	}
+	
+	private MimeMessage getBasicMimeMessage() throws Exception {
+		log.debug("getBasicMimeMessage");
+
+		// Evaluating Configuration Data
+		String smtpServer = cfgDao.getConfValue("smtp_server", String.class, null);
+		String smtpPort = cfgDao.getConfValue("smtp_port", String.class, "25");
+		String from = cfgDao.getConfValue("system_email_addr", String.class, null);
+		String mailAuthUser = cfgDao.getConfValue("email_username", String.class, null);
+		String mailAuthPass = cfgDao.getConfValue("email_userpass", String.class, null);
+
+		Properties props = System.getProperties();
+
+		props.put("mail.smtp.host", smtpServer);
+		props.put("mail.smtp.port", smtpPort);
+
+		if ("1".equals(cfgDao.getConfValue("mail.smtp.starttls.enable", String.class, "0"))) {
+			props.put("mail.smtp.starttls.enable", "true");
+		}
+
+		// Check for Authentication
+		Session session = null;
+		if (mailAuthUser != null && mailAuthUser.length() > 0
+				&& mailAuthPass != null && mailAuthPass.length() > 0) {
+			// use SMTP Authentication
+			props.put("mail.smtp.auth", "true");
+			session = Session.getDefaultInstance(props, new SmtpAuthenticator(mailAuthUser, mailAuthPass));
+		} else {
+			// not use SMTP Authentication
+			session = Session.getDefaultInstance(props, null);
+		}
+
+		// Building MimeMessage
+		MimeMessage msg = new MimeMessage(session);
+		msg.setFrom(new InternetAddress(from));
+		return msg;
+	}
+	
+	private MimeMessage getMimeMessage(MailMessage m) throws Exception {
+		log.debug("getMimeMessage");
+		// Building MimeMessage
+		MimeMessage msg = getBasicMimeMessage();
+		msg.setSubject(m.getSubject());
+		String replyTo = m.getReplyTo();
+		if (replyTo != null && "1".equals(cfgDao.getConfValue("inviter.email.as.replyto",
String.class, "1"))) {
+			log.debug("setReplyTo " + replyTo);
+			if (MailUtil.matches(replyTo)) {
+				msg.setReplyTo(new InternetAddress[]{new InternetAddress(replyTo)});
+			}
+		}
+		msg.addRecipients(Message.RecipientType.TO, InternetAddress.parse(m.getRecipients(), false));
+		
+		return m.getIcs() == null ? appendBody(msg, m) : appendIcsBody(msg, m);
+	}
+	
+	public void send(String toEmail, String subj, String message) {
+		send(toEmail, null, subj, message);
+	}
+	
+	public void send(String toEmail, String replyTo, String subj, String message) {
+		send(new MailMessage(toEmail, replyTo, subj, message));
+	}
+	
+	public void send(MailMessage m) {
+		send(m, false);
+	}
+	
+	public void send(final MailMessage m, boolean send) {
+		if (send) {
+			if (m.getId() != 0) {
+				m.setStatus(Status.SENDING);
+				mailMessageDao.update(m, null);
+			}
+			taskExecutor.execute(new Runnable() {
+				public void run() {
+					log.debug("Message sending in progress");
+					log.debug("  To: " + m.getRecipients());
+					log.debug("  Subject: " + m.getSubject());
+
+					// -- Send the message --
+					try {
+						Transport.send(getMimeMessage(m));
+						m.setStatus(Status.DONE);
+					} catch (Exception e) {
+						log.error("Error while sending message", e);
+						m.setStatus(Status.NONE);
+					}
+					if (m.getId() != 0) {
+						mailMessageDao.update(m, null);
+					}
+				}
+			});
+		} else {
+			m.setStatus(Status.NONE);
+			mailMessageDao.update(m, null);
+		}
+	}
+	
+	public void resetSendingStatus() {
+		log.debug("resetSendingStatus enter ...");
+		Calendar c = Calendar.getInstance();
+		c.add(Calendar.MILLISECOND, -MAIL_SEND_TIMEOUT);
+		mailMessageDao.resetSendingStatus(c);
+		log.debug("... resetSendingStatus done.");
+	}
+	
+	public void sendMails() {
+		log.debug("sendMails enter ...");
+		List<MailMessage> list = mailMessageDao.get(0, 1);
+		while (!list.isEmpty()) {
+			send(list.get(0), true);
+			list = mailMessageDao.get(0, 1);
 		}
+		log.debug("... sendMails done.");
 	}
 }



Mime
View raw message