return handleSending(mapping, form, req, resp, calendar.getTime());
}
/* handles all form evaluation and preparing of sending for direct and scheduled sending */
private ActionForward handleSending(ActionMapping mapping, ActionForm form,HttpServletRequest req, HttpServletResponse resp, Date sendAt) {
EmailSendForm emailSendForm = (EmailSendForm)form;
if (isTokenValid(req)) {
resetToken(req);
saveToken(req);
} else {
String invalidToken = getResources(req).getMessage(locale,"smssvc.invalidTokenOnSend");
req.setAttribute("generalError", invalidToken);
// reset also confirmation pending because enter will not be called
emailSendForm.setSendConfirmationPending(false);
return mapping.findForward("invalidToken");
}
EmailAddress fromAddress = new EmailAddress(webUser,emailSendForm.getFromEmail(),emailSendForm.getFromPersonalName() == null ? null : emailSendForm.getFromPersonalName());
Long userSetId = emailSendForm.getUserSetId();
Long userId = emailSendForm.getUserId();
Set<User> users=null;
Integer destinationSelection = emailSendForm.getDestinationSelection();
switch (destinationSelection==null?0:destinationSelection){
case 1: // user set
UserSetManager userSetManager = new UserSetManager(locale,session);
if (userSetId.longValue() == -1){
String noUserSetSelectedString = getResources(req).getMessage(locale,"smssvc.MessageNotSentBecauseNoUserSetSelected");
req.setAttribute("generalError",noUserSetSelectedString);
return mapping.findForward("notSent");
}
UserSet userSet = userSetManager.getUserSet(userSetId);
if (userSet == null){
throw new ConfigurationException("illegal user set id: " + userSetId);
}
users = userSet.getUsers();
break;
case 2: // user
if (userId.longValue() == -1){
String noUserSelectedString = getResources(req).getMessage(locale,"smssvc.MessageNotSentBecauseNoUserSelected");
req.setAttribute("generalError",noUserSelectedString);
return mapping.findForward("notSent");
}
UserManager userManager = new UserManager(locale,session);
User user = userManager.getUserDetails(userId);
if (user == null){
throw new ConfigurationException("illegal user id: " + user);
}
Set<User> oneManSet = new HashSet<User>();
oneManSet.add(user);
users = oneManSet;
break;
case 3: // e-mail address
EmailAddress toAddress = new EmailAddress(emailSendForm.getToEmail(), emailSendForm.getToPersonalName());
SortedSet<EmailAddress> receivers = new TreeSet<EmailAddress>();
receivers.add(toAddress);
MessagingManager msgMgr = new MessagingManager(locale, session);
msgMgr.sendEmail(fromAddress, receivers, getCurrentGroup(req), emailSendForm.getSubject(), emailSendForm.getMessage(), emailSendForm.getMimeType() == null ? MailSender.MIME_TYPE_PLAIN_TEXT : emailSendForm.getMimeType().intValue(), sendAt);
Date date = new Date(System.currentTimeMillis());
String formattedDate = DateFormat.getTimeInstance(DateFormat.MEDIUM,locale).format(date);
String generalInformation = getResources(req).getMessage(locale, "smssvc.asyncSendStarted", new Object[] {new Integer(receivers.size()), formattedDate});
req.setAttribute("generalInformation", generalInformation);
return mapping.findForward("sent");
default:
String noDestinationSelectedString = getResources(req).getMessage(locale,"smssvc.noDestinationSelected");
req.setAttribute("generalError",noDestinationSelectedString);
return mapping.findForward("notSent");
}
if (users != null && users.size() >= CONFIRMATION_MINIMUM && !emailSendForm.isSendConfirmationPending()){
emailSendForm.setSendConfirmationPending(true);
String msg = getResources(req).getMessage(locale, "smssvc.ConfirmSendToManyReceivers.", users.size());
req.setAttribute("generalError", msg);
return mapping.findForward("confirm");
} else {
emailSendForm.setSendConfirmationPending(false);
return sendToUsersWithEmail(fromAddress, users,mapping,form,req,resp, sendAt);
}
}