Search in sources :

Example 1 with MailMessage

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());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) UserRepository(com.axelor.auth.db.repo.UserRepository) MetaAttachment(com.axelor.meta.db.MetaAttachment) Templates(com.axelor.text.Templates) Filter(com.axelor.rpc.filter.Filter) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) MessagingException(javax.mail.MessagingException) StringTemplates(com.axelor.text.StringTemplates) Map(java.util.Map) MailBuilder(com.axelor.mail.MailBuilder) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Path(java.nio.file.Path) MailServiceMessageImpl(com.axelor.apps.message.service.MailServiceMessageImpl) MailFollower(com.axelor.mail.db.MailFollower) MethodHandles(java.lang.invoke.MethodHandles) Set(java.util.Set) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StringUtils(com.axelor.common.StringUtils) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) List(java.util.List) MailException(com.axelor.mail.MailException) StringUtils.isBlank(com.axelor.common.StringUtils.isBlank) MailFollowerRepository(com.axelor.mail.db.repo.MailFollowerRepository) Partner(com.axelor.apps.base.db.Partner) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MailAddress(com.axelor.mail.db.MailAddress) Joiner(com.google.common.base.Joiner) Query(com.axelor.db.Query) MailTemplateAssociation(com.axelor.apps.base.db.MailTemplateAssociation) EntityHelper(com.axelor.db.EntityHelper) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) MailSender(com.axelor.mail.MailSender) Singleton(javax.inject.Singleton) MailMessageRepository(com.axelor.mail.db.repo.MailMessageRepository) MailService(com.axelor.mail.service.MailService) ArrayList(java.util.ArrayList) InternetAddress(javax.mail.internet.InternetAddress) Strings(com.google.common.base.Strings) GroovyTemplates(com.axelor.text.GroovyTemplates) Predicates(com.google.common.base.Predicates) MailMessage(com.axelor.mail.db.MailMessage) LinkedHashSet(java.util.LinkedHashSet) ExecutorService(java.util.concurrent.ExecutorService) MetaFiles(com.axelor.meta.MetaFiles) Logger(org.slf4j.Logger) Model(com.axelor.db.Model) JpaSecurity(com.axelor.db.JpaSecurity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TraceBackService(com.axelor.exception.service.TraceBackService) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) IOException(java.io.IOException) MimeMessage(javax.mail.internet.MimeMessage) TemplateRepository(com.axelor.apps.message.db.repo.TemplateRepository) Maps(com.google.common.collect.Maps) Template(com.axelor.apps.message.db.Template) File(java.io.File) Beans(com.axelor.inject.Beans) EmailAccount(com.axelor.apps.message.db.EmailAccount) Preconditions(com.google.common.base.Preconditions) TemplateMessageService(com.axelor.apps.message.service.TemplateMessageService) User(com.axelor.auth.db.User) MailFollowerRepository(com.axelor.mail.db.repo.MailFollowerRepository) MailAddress(com.axelor.mail.db.MailAddress) User(com.axelor.auth.db.User) MailFollower(com.axelor.mail.db.MailFollower) Partner(com.axelor.apps.base.db.Partner)

Example 2 with MailMessage

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;
}
Also used : MailMessage(com.axelor.mail.db.MailMessage) Document(org.jsoup.nodes.Document)

Example 3 with MailMessage

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);
}
Also used : MailMessageRepository(com.axelor.mail.db.repo.MailMessageRepository) MailMessage(com.axelor.mail.db.MailMessage) Mapper(com.axelor.db.mapper.Mapper) User(com.axelor.auth.db.User) Transactional(com.google.inject.persist.Transactional)

Aggregations

MailMessage (com.axelor.mail.db.MailMessage)3 User (com.axelor.auth.db.User)2 MailMessageRepository (com.axelor.mail.db.repo.MailMessageRepository)2 MailTemplateAssociation (com.axelor.apps.base.db.MailTemplateAssociation)1 Partner (com.axelor.apps.base.db.Partner)1 PartnerRepository (com.axelor.apps.base.db.repo.PartnerRepository)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 EmailAccount (com.axelor.apps.message.db.EmailAccount)1 Template (com.axelor.apps.message.db.Template)1 TemplateRepository (com.axelor.apps.message.db.repo.TemplateRepository)1 MailServiceMessageImpl (com.axelor.apps.message.service.MailServiceMessageImpl)1 TemplateMessageService (com.axelor.apps.message.service.TemplateMessageService)1 UserRepository (com.axelor.auth.db.repo.UserRepository)1 StringUtils (com.axelor.common.StringUtils)1 StringUtils.isBlank (com.axelor.common.StringUtils.isBlank)1 EntityHelper (com.axelor.db.EntityHelper)1 JpaSecurity (com.axelor.db.JpaSecurity)1 Model (com.axelor.db.Model)1 Query (com.axelor.db.Query)1 Mapper (com.axelor.db.mapper.Mapper)1