Skip to content

Commit

Permalink
SAK-44902: Broken links on messages tool received from a mail client. (
Browse files Browse the repository at this point in the history
…sakaiproject#8971)

* SAK-44902: Broken links on messages tool received from a mail client.

* SAK-44902: Resolve Issues

* SAK-44902: change error handling

* Update mailarchive/mailarchive-subetha/src/bundle/sakaimailet.properties

Co-authored-by: Shawn Foster <[email protected]>

Co-authored-by: Shawn Foster <[email protected]>
  • Loading branch information
victorGomollon and fostersdesign authored Mar 10, 2021
1 parent 3b46f4c commit 1bb6b64
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ mail.support.683=Sender's email does not belong in Sakai, nor is it recognized a
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.
mail.support.358=Message body has characters that cannot be used. Please look over your email content and try again. You can also reply from the Messages tool.
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ mail.support.683=El email del remitente no pertenece al aula virtual, ni es reco
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.

mail.support.358=El cuerpo del corre contiene caracteres extraños que no se pueden tratar, por favor revise el correo e intentelo de nuevo o responda desde la herramienta mensajes privados.
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ public class SakaiMessageHandlerFactory implements MessageHandlerFactory {
*/
public static final String POSTMASTER = "postmaster";
public static final String FROM_REPLY = "msgcntr.messages.header.from.reply";
public static final String MESSAGE_ERROR_682 = "682";
public static final String MESSAGE_ERROR_358 = "358";
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";
public static final String MESSAGE_ERROR_521 = "521";
public static final String MESSAGE_ERROR_682 = "682";
public static final String MESSAGE_ERROR_683 = "683";

private SMTPServer server;

Expand Down Expand Up @@ -370,30 +371,16 @@ public void data(InputStream data) throws RejectException, IOException {
}
} catch (MessagingException me) {
// INDICATES that the channel is NOT currently enabled so no messages can be received
if (me.getMessage().startsWith(MESSAGE_ERROR_682)) {
String mailSupport = StringUtils.trimToNull(serverConfigurationService.getString("mail.support"));
String messageNumber = me.getMessage().replaceAll("(\\d+).+", "$1");
String errMsg = rb.getString("mail.support." + messageNumber);
if (StringUtils.isNotBlank(errMsg)) {
// BOUNCE REPLY - send a message back to the user to let them know their email failed
String errMsg = rb.getString("mail.support.682") + "\n\n";
String mailSupport = StringUtils.trimToNull(serverConfigurationService.getString("mail.support"));
if (StringUtils.isNotBlank(mailSupport)) {
errMsg += rb.getFormattedMessage("err_questions", mailSupport) + "\n";
}
throw new RejectException(Integer.parseInt(MESSAGE_ERROR_682), errMsg);
} else if (me.getMessage().startsWith(MESSAGE_ERROR_359)) {
// BOUNCE REPLY - send a message back to the user to let them know their email failed
String errMsg = rb.getString("mail.support.359") + "\n\n";
String mailSupport = StringUtils.trimToNull(serverConfigurationService.getString("mail.support"));
if (StringUtils.isNotBlank(mailSupport)) {
errMsg += rb.getFormattedMessage("err_questions", mailSupport) + "\n";
}
throw new RejectException(Integer.parseInt(MESSAGE_ERROR_359), errMsg);
} else if (me.getMessage().startsWith(MESSAGE_ERROR_683)) {
// BOUNCE REPLY - send a message back to the user to let them know their email failed
String errMsg = rb.getString("mail.support.683") + "\n\n";
String mailSupport = StringUtils.trimToNull(serverConfigurationService.getString("mail.support"));
errMsg = errMsg + "\n\n";
if (StringUtils.isNotBlank(mailSupport)) {
errMsg += rb.getFormattedMessage("err_questions", mailSupport) + "\n";
}
throw new RejectException(Integer.parseInt(MESSAGE_ERROR_683), errMsg);
throw new RejectException(Integer.parseInt(messageNumber), errMsg);
} else {
throw new RejectException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
import org.sakaiproject.user.api.User;
import org.sakaiproject.user.api.UserDirectoryService;
import org.sakaiproject.user.api.UserNotDefinedException;
import org.sakaiproject.util.api.FormattedText;
import org.sakaiproject.util.ResourceLoader;

@Slf4j
Expand Down Expand Up @@ -143,6 +144,8 @@ public class PrivateMessageManagerImpl extends HibernateDaoSupport implements Pr
private LearningResourceStoreService learningResourceStoreService;
@Setter private PreferencesService preferencesService;
@Setter private ServerConfigurationService serverConfigurationService;
@Setter private FormattedText formattedText;

private static final String MESSAGES_TITLE = "pvt_message_nav";// Mensajes-->Messages/need to be modified to support internationalization

private static final String PVT_RECEIVED = "pvt_received"; // Recibidos ( 0 mensajes )-->Received ( 8 messages - 8 unread )
Expand Down Expand Up @@ -2163,12 +2166,24 @@ public PrivateMessage getPvtMsgReplyMessage(PrivateMessage currentMessage, MimeM

PrivateMessage rrepMsg = createResponseMessage(currentMessage, msg, from);

if (StringUtils.isNotBlank(bodyBuf[0].toString())) {
bodyBuf[0].insert(0, "<pre>");
bodyBuf[0].insert(bodyBuf[0].length(), "</pre>");
rrepMsg.setBody(bodyBuf[0].toString());

StringBuilder alertMsg = new StringBuilder();
StringBuilder cleanBody;
if (StringUtils.isNotBlank(bodyBuf[1].toString())) {
cleanBody = new StringBuilder(formattedText.processFormattedText(bodyBuf[1].toString(), alertMsg));
} else {
rrepMsg.setBody(bodyBuf[1].toString());
cleanBody = new StringBuilder(formattedText.escapeHtml(bodyBuf[0].toString()));
if(StringUtils.isNotBlank(cleanBody)) {
cleanBody.insert(0, "<pre>");
cleanBody.insert(cleanBody.length(), "</pre>");
}
}

if(StringUtils.isBlank(cleanBody)) {
log.warn("358 - Unexpected error processing text of body.");
throw new MessagingException("358 - Unexpected error processing text of body.");
}else {
rrepMsg.setBody(cleanBody.toString());
}
rrepMsg.setLabel(currentMessage.getLabel());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
<property name="learningResourceStoreService" ref="org.sakaiproject.event.api.LearningResourceStoreService"/>
<property name="preferencesService" ref="org.sakaiproject.user.api.PreferencesService"/>
<property name="serverConfigurationService" ref="org.sakaiproject.component.api.ServerConfigurationService"/>
<property name="formattedText" ref="org.sakaiproject.util.api.FormattedText" />
</bean>
</property>
<property name="transactionAttributes">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ PageParts parseHtmlParts(String responseStr, boolean debug) {
// this so we will do the same - so that we can be
// somewhat clean - we search for the "last" end
// body tag - for the normal case there will only be one
int bodyEnd = StringUtils.indexOfIgnoreCase(responseStr, "</body");
int bodyEnd = StringUtils.lastIndexOfIgnoreCase(responseStr, "</body");
// If there is no body end at all or it is before the body
// start tag we simply - take the rest of the response
if ( bodyEnd < bodyStart ) bodyEnd = responseStr.length() - 1;
Expand Down

0 comments on commit 1bb6b64

Please sign in to comment.