Skip to content

Commit

Permalink
SAK-44638: Bugs fixes for SAK-42856: Message destination error (sakai…
Browse files Browse the repository at this point in the history
…project#8796)

* SAK-44638: Bugs fixes for SAK-42856: Message destination error

* SAK-44638: Resolved Issues

* SAK-44638: Resolved issues

* SAK-44638: Midified name properties
  • Loading branch information
victorGomollon authored Dec 3, 2020
1 parent ec1ca3d commit b8e3b02
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2821,8 +2821,8 @@
# msgcntr.messages.header.from.reply=reply-msg-id_
# Spam control. This number caps the maximum number of email replies from every user
# msgcntr.no.reply.max.respond=5
# Token used to encrypt / decrypt an e-mail ID. Must be 16 char long.
# msgcntr.no.reply.secret=6355384263553842
# Token used to encrypt / decrypt an e-mail ID. Must be 8 char long.
# sakai.encryption.secret=11111111
# Allows to answer emails from desktop application
# DEFAULT: none, ACTIVE: all, Specify the contextID to limit it to just one site, Ej:"1900_G_2019_N_N"
# msgcntr.messages.user.real.reply=all
Expand All @@ -2835,8 +2835,8 @@
# msgcntr.messages.header.from.reply=reply-msg-id_
# Spam control. This number caps the maximum number of email replies from every user
# msgcntr.no.reply.max.respond=5
# Token used to encrypt / decrypt an e-mail ID. Must be 16 char long.
# msgcntr.no.reply.secret=6355384263553842
# Token used to encrypt / decrypt an e-mail ID. Must be 8 char long.
# sakai.encryption.secret=11111111
# Allows to answer emails from desktop application
# DEFAULT: none, ACTIVE: all, Specify the contextID to limit it to just one site, Ej:"1900_G_2019_N_N"
# msgcntr.messages.user.real.reply=all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ mail.support.682=The maximum number of responses for the sender's mail address h
mail.support.359=Sender's email address does not belong to any of the mail original recipients. If you are replying from an address different than the one from which you received the email, please use the correct email address to reply to it.

mail.support.683=Sender's email does not belong in Sakai, nor is it recognized as an automatic forwarding address. If you have replied to this email from an address other than the one you have configured for email forwarding, please reply from that address.
mail.support.521=Destination address of this e-mail couldn't be retrieved. Please, reply this message from Sakai's Messages tool.
mail.support.421=Your email could not be sent due to connectivity problems. Please, try again later.
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ mail.support.682=Se ha superado el n\u00FAmero m\u00e1ximo de respuestas para la
mail.support.359=El email del remitente no pertenece a los destinatarios originales del correo. Si usted esta contestando desde una direcci\u00f3n de correo distinta desde la que recibi\u00f3 el correo, por favor utilice la direcci\u00f3n correcta para responder al mismo.

mail.support.683=El email del remitente no pertenece al aula virtual, ni es reconocido como direcci\u00f3n de reenv\u00edo autom\u00e1tico. Si ha respondido a este correo desde otra direcci\u00f3n distinta al cual tiene configurado para el reenv\u00edo de correos, por favor conteste desde esa misma direcci\u00f3n.

mail.support.521=No se ha podido recupera la direcci\u00f3n destino del correo. Por favor, responda a este mensaje desde la herramienta de mensajes privados del Aula Virtual.

mail.support.421=No se ha podido enviar su correo electr\u00f3nico por problemas de conectividad. Por favor, intentelo de nuevo mas tarde.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public class SakaiMessageHandlerFactory implements MessageHandlerFactory {
public static final String MESSAGE_ERROR_682 = "682";
public static final String MESSAGE_ERROR_359 = "359";
public static final String MESSAGE_ERROR_683 = "683";
public static final String MESSAGE_ERROR_521 = "521";
public static final String MESSAGE_ERROR_421 = "421";

private SMTPServer server;

Expand Down Expand Up @@ -185,7 +187,24 @@ public void recipient(String to) throws RejectException {
if (StringUtils.isNotBlank(fromReply) && to.startsWith(serverConfigurationService.getString(FROM_REPLY, StringUtils.EMPTY))) {
isMessageId = true;
String id = to.replace(serverConfigurationService.getString(FROM_REPLY), StringUtils.EMPTY).split("@")[0];
currentMessage = synopticMsgcntrManager.getPvtMessageManager().getPrivateMessage(id);
try {
currentMessage = synopticMsgcntrManager.getPvtMessageManager().getPrivateMessage(id);
} catch (MessagingException me) {
String mailSupport = StringUtils.trimToNull(serverConfigurationService.getString("mail.support"));
if (me.getMessage().startsWith(MESSAGE_ERROR_521)) {
// BOUNCE REPLY - send a message back to the user to let them know their email failed
String errMsg = rb.getString("mail.support.521") + "\n\n";
if (StringUtils.isNotBlank(mailSupport)) {
errMsg += rb.getFormattedMessage("err_questions", mailSupport) + "\n";
}
throw new RejectException(Integer.parseInt(MESSAGE_ERROR_521), errMsg);
}
String errMsg = rb.getString("mail.support.421") + "\n\n";
if (StringUtils.isNotBlank(mailSupport)) {
errMsg += rb.getFormattedMessage("err_questions", mailSupport) + "\n";
}
throw new RejectException(Integer.parseInt(MESSAGE_ERROR_421), errMsg);
}
} else if (serverConfigurationService.getServerName().equalsIgnoreCase(address.getDomain())) {
isMessageId = false;
Recipient recipient = new Recipient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public List getMessagesByTypeByContext(final String typeUuid, final String conte
public PrivateMessage getPreviousMessage(PrivateMessage message);
public boolean hasPreviousMessage(PrivateMessage message);
public boolean hasNextMessage(PrivateMessage message);
public PrivateMessage getPrivateMessage(final String id);
public PrivateMessage getPrivateMessage(final String id) throws MessagingException;
public Map<User, Boolean> getRecipients(List recipients);
public PrivateMessage getPvtMsgReplyMessage(PrivateMessage currentMessage, MimeMessage msg, StringBuilder[] bodyBuf, List<Reference> attachments, String from) throws MessagingException;
public void processPvtMsgReplySentAction(PrivateMessage currentMessage, PrivateMessage rrepMsg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.LockMode;
Expand Down Expand Up @@ -155,7 +156,7 @@ public class PrivateMessageManagerImpl extends HibernateDaoSupport implements Pr
private static final String EMAIL_FOOTER3 = "pvt_email_footer3";
private static final String EMAIL_FOOTER4_A = "pvt_email_footer4_a";
private static final String EMAIL_FOOTER4_B = "pvt_email_footer4_b";
private static final String INIT_VECTOR = "RandomInitVector";
private static final String INIT_VECTOR = "RandomIn";

private ResourceLoader rb;

Expand Down Expand Up @@ -2104,7 +2105,7 @@ else if (toolId.equals(DiscussionForumService.MESSAGES_TOOL_ID))
return eventMessagePrefix + contextId + "/" + object.toString() + "/" + userId;
}

public PrivateMessage getPrivateMessage(final String id) {
public PrivateMessage getPrivateMessage(final String id) throws MessagingException {
PrivateMessage currentMessage = (PrivateMessage) messageManager.getMessageByIdWithAttachments(Long.parseLong(decrypt(id)));
getHibernateTemplate().initialize(currentMessage.getRecipients());
return currentMessage;
Expand Down Expand Up @@ -2274,15 +2275,15 @@ public void processPvtMsgReplySentAction(PrivateMessage currentMessage, PrivateM
private String encrypt(String value) {
try {
IvParameterSpec iv = new IvParameterSpec(INIT_VECTOR.getBytes(StandardCharsets.UTF_8));
String key = serverConfigurationService.getString("msgcntr.no.reply.secret", "1111111111111111");
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
String key = serverConfigurationService.getString("sakai.encryption.secret", serverConfigurationService.getServerName());
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "DES");

Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5PADDING");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);

byte[] encrypted = cipher.doFinal(value.getBytes(StandardCharsets.UTF_8));

return Base64.encodeBase64String(encrypted);
return Hex.encodeHexString(Base64.encodeBase64String(encrypted).getBytes(StandardCharsets.UTF_8));

} catch (Exception ex) {
log.error(ex.getMessage(), ex);
Expand All @@ -2291,23 +2292,23 @@ private String encrypt(String value) {
return null;
}

private String decrypt(String encrypted) {
private String decrypt(String encrypted) throws MessagingException {
try {
String hexencrypted = new String(Hex.decodeHex(encrypted.toLowerCase().toCharArray()),StandardCharsets.UTF_8);
IvParameterSpec iv = new IvParameterSpec(INIT_VECTOR.getBytes(StandardCharsets.UTF_8));
String key = serverConfigurationService.getString("msgcntr.no.reply.secret", "1111111111111111");
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
String key = serverConfigurationService.getString("sakai.encryption.secret", serverConfigurationService.getServerName());
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "DES");

Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);

byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted));
byte[] original = cipher.doFinal(Base64.decodeBase64(hexencrypted));

return new String(original,StandardCharsets.UTF_8);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
log.warn("Exception: Recipient couldn't be obtained. Please, reply to this mail from Sakai's private messages tool.");
throw new MessagingException("521 - Recipient couldn't be obtained. Please, reply to this mail from Sakai's private messages tool.");
}

return null;
}

private LRS_Statement getStatementForUserSentPvtMsg(String subject, SAKAI_VERB sakaiVerb, PrivateMessage rrepMsg) {
Expand Down

0 comments on commit b8e3b02

Please sign in to comment.