use of com.axelor.mail.db.MailMessage in project axelor-open-suite by axelor.
the class MailServiceBaseImpl method recipients.
@Override
protected Set<String> recipients(MailMessage message, Model entity) {
final Set<String> recipients = new LinkedHashSet<>();
final MailFollowerRepository followers = Beans.get(MailFollowerRepository.class);
String entityName = entity.getClass().getName();
if (message.getRecipients() != null) {
for (MailAddress address : message.getRecipients()) {
recipients.add(address.getAddress());
}
}
for (MailFollower follower : followers.findAll(message)) {
if (follower.getArchived()) {
continue;
}
User user = follower.getUser();
if (user != null) {
if (!(user.getReceiveEmails() && user.getFollowedMetaModelSet().stream().anyMatch(x -> x.getFullName().equals(entityName)))) {
continue;
} else {
Partner partner = user.getPartner();
if (partner != null && partner.getEmailAddress() != null) {
recipients.add(partner.getEmailAddress().getAddress());
} else if (user.getEmail() != null) {
recipients.add(user.getEmail());
}
}
} else {
if (follower.getEmail() != null) {
recipients.add(follower.getEmail().getAddress());
} else {
log.info("No email address found for follower : " + follower);
}
}
}
return Sets.filter(recipients, Predicates.notNull());
}
use of com.axelor.mail.db.MailMessage in project axelor-open-suite by axelor.
the class MailServiceHelpDeskImpl method messageReceived.
@Override
protected MailMessage messageReceived(MimeMessage email) throws MessagingException, IOException {
MailMessage message = super.messageReceived(email);
if (!Beans.get(AppService.class).isApp("helpdesk")) {
return message;
}
Document doc = Jsoup.parse(message.getBody());
doc.select("div.gmail_extra").remove();
message.setBody(doc.outerHtml());
return message;
}
use of com.axelor.mail.db.MailMessage in project axelor-open-suite by axelor.
the class StudioMetaService method trackingFields.
@Transactional
public void trackingFields(AuditableModel auditableModel, String messageBody, String messageSubject) {
User user = AuthUtils.getUser();
MailMessage message = new MailMessage();
Mapper mapper = Mapper.of(auditableModel.getClass());
message.setSubject(messageSubject);
message.setAuthor(user);
message.setBody(messageBody);
message.setRelatedId(auditableModel.getId());
message.setRelatedModel(EntityHelper.getEntityClass(auditableModel).getName());
message.setType(MailConstants.MESSAGE_TYPE_NOTIFICATION);
message.setRelatedName(mapper.getNameField().get(auditableModel).toString());
Beans.get(MailMessageRepository.class).save(message);
}
Aggregations