Search in sources :

Example 41 with Message

use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.

the class DebtRecoveryActionService method runStandardMessage.

/**
 * Fonction permettant de créer un courrier à destination des tiers pour un contrat standard
 *
 * @param debtRecovery
 * @return
 * @throws AxelorException
 * @throws ClassNotFoundException
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws IOException
 */
public Set<Message> runStandardMessage(DebtRecovery debtRecovery) throws AxelorException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
    Set<Message> messages = new HashSet<>();
    DebtRecoveryMethodLine debtRecoveryMethodLine = debtRecovery.getDebtRecoveryMethodLine();
    Set<Template> templateSet = debtRecoveryMethodLine.getMessageTemplateSet();
    DebtRecoveryHistory debtRecoveryHistory = this.getDebtRecoveryHistory(debtRecovery);
    for (Template template : templateSet) {
        messages.add(templateMessageAccountService.generateMessage(debtRecoveryHistory, template));
    }
    return messages;
}
Also used : DebtRecoveryHistory(com.axelor.apps.account.db.DebtRecoveryHistory) IExceptionMessage(com.axelor.apps.account.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message) DebtRecoveryMethodLine(com.axelor.apps.account.db.DebtRecoveryMethodLine) HashSet(java.util.HashSet) Template(com.axelor.apps.message.db.Template)

Example 42 with Message

use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.

the class MessageServiceBaseImpl method createMessage.

@Override
@Transactional
public Message createMessage(String model, long id, String subject, String content, EmailAddress fromEmailAddress, List<EmailAddress> replyToEmailAddressList, List<EmailAddress> toEmailAddressList, List<EmailAddress> ccEmailAddressList, List<EmailAddress> bccEmailAddressList, Set<MetaFile> metaFiles, String addressBlock, int mediaTypeSelect, EmailAccount emailAccount, String signature) {
    Message message = super.createMessage(model, id, subject, content, fromEmailAddress, replyToEmailAddressList, toEmailAddressList, ccEmailAddressList, bccEmailAddressList, metaFiles, addressBlock, mediaTypeSelect, emailAccount, signature);
    message.setSenderUser(AuthUtils.getUser());
    message.setCompany(userService.getUserActiveCompany());
    return messageRepository.save(message);
}
Also used : Message(com.axelor.apps.message.db.Message) Transactional(com.google.inject.persist.Transactional)

Example 43 with Message

use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.

the class MailAccountServiceImpl method createMessage.

@Transactional(rollbackOn = { Exception.class })
public Message createMessage(EmailAccount mailAccount, MailParser parser, Date date) throws MessagingException {
    Message message = new Message();
    message.setMailAccount(mailAccount);
    message.setTypeSelect(MessageRepository.TYPE_SENT);
    message.setMediaTypeSelect(MessageRepository.MEDIA_TYPE_EMAIL);
    message.setFromEmailAddress(getEmailAddress(parser.getFrom()));
    message.setCcEmailAddressSet(getEmailAddressSet(parser.getCc()));
    message.setBccEmailAddressSet(getEmailAddressSet(parser.getBcc()));
    message.setToEmailAddressSet(getEmailAddressSet(parser.getTo()));
    message.addReplyToEmailAddressSetItem(getEmailAddress(parser.getReplyTo()));
    message.setContent(parser.getHtml());
    message.setSubject(parser.getSubject());
    message.setSentDateT(DateTool.toLocalDateT(date));
    message = messageRepo.save(message);
    List<DataSource> attachments = parser.getAttachments();
    addAttachments(message, attachments);
    return message;
}
Also used : Message(com.axelor.apps.message.db.Message) MimeMessage(javax.mail.internet.MimeMessage) IExceptionMessage(com.axelor.apps.message.exception.IExceptionMessage) DataSource(javax.activation.DataSource) Transactional(com.google.inject.persist.Transactional)

Example 44 with Message

use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.

the class MailAccountServiceImpl method fetchEmails.

@Override
public int fetchEmails(EmailAccount mailAccount, boolean unseenOnly) throws MessagingException, IOException {
    if (mailAccount == null) {
        return 0;
    }
    log.debug("Fetching emails from host: {}, port: {}, login: {} ", mailAccount.getHost(), mailAccount.getPort(), mailAccount.getLogin());
    com.axelor.mail.MailAccount account = null;
    if (mailAccount.getServerTypeSelect().equals(EmailAccountRepository.SERVER_TYPE_IMAP)) {
        account = new ImapAccount(mailAccount.getHost(), mailAccount.getPort().toString(), mailAccount.getLogin(), mailAccount.getPassword(), getSecurity(mailAccount));
    } else {
        account = new Pop3Account(mailAccount.getHost(), mailAccount.getPort().toString(), mailAccount.getLogin(), mailAccount.getPassword(), getSecurity(mailAccount));
    }
    MailReader reader = new MailReader(account);
    final Store store = reader.getStore();
    final Folder inbox = store.getFolder("INBOX");
    // open as READ_WRITE to mark messages as seen
    inbox.open(Folder.READ_WRITE);
    // find all unseen messages
    final FetchProfile profile = new FetchProfile();
    javax.mail.Message[] messages;
    if (unseenOnly) {
        final FlagTerm unseen = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
        messages = inbox.search(unseen);
    } else {
        messages = inbox.getMessages();
    }
    profile.add(FetchProfile.Item.ENVELOPE);
    // actually fetch the messages
    inbox.fetch(messages, profile);
    log.debug("Total emails unseen: {}", messages.length);
    int count = 0;
    for (javax.mail.Message message : messages) {
        if (message instanceof MimeMessage) {
            MailParser parser = new MailParser((MimeMessage) message);
            parser.parse();
            createMessage(mailAccount, parser, message.getSentDate());
            count++;
        }
    }
    log.debug("Total emails fetched: {}", count);
    return count;
}
Also used : FetchProfile(javax.mail.FetchProfile) ImapAccount(com.axelor.mail.ImapAccount) Pop3Account(com.axelor.mail.Pop3Account) Message(com.axelor.apps.message.db.Message) MimeMessage(javax.mail.internet.MimeMessage) IExceptionMessage(com.axelor.apps.message.exception.IExceptionMessage) MailParser(com.axelor.mail.MailParser) Store(javax.mail.Store) Flags(javax.mail.Flags) Folder(javax.mail.Folder) MailReader(com.axelor.mail.MailReader) FlagTerm(javax.mail.search.FlagTerm) MimeMessage(javax.mail.internet.MimeMessage)

Example 45 with Message

use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.

the class MessageServiceImpl method createMessage.

@Override
@Transactional
public Message createMessage(String model, long id, String subject, String content, EmailAddress fromEmailAddress, List<EmailAddress> replyToEmailAddressList, List<EmailAddress> toEmailAddressList, List<EmailAddress> ccEmailAddressList, List<EmailAddress> bccEmailAddressList, Set<MetaFile> metaFiles, String addressBlock, int mediaTypeSelect, EmailAccount emailAccount, String signature) {
    emailAccount = emailAccount != null ? Beans.get(EmailAccountRepository.class).find(emailAccount.getId()) : emailAccount;
    Message message = createMessage(content, fromEmailAddress, model, id, null, 0, false, MessageRepository.STATUS_DRAFT, subject, MessageRepository.TYPE_SENT, replyToEmailAddressList, toEmailAddressList, ccEmailAddressList, bccEmailAddressList, addressBlock, mediaTypeSelect, emailAccount, signature);
    messageRepository.save(message);
    attachMetaFiles(message, metaFiles);
    return message;
}
Also used : EmailAccountRepository(com.axelor.apps.message.db.repo.EmailAccountRepository) Message(com.axelor.apps.message.db.Message) IExceptionMessage(com.axelor.apps.message.exception.IExceptionMessage) Transactional(com.google.inject.persist.Transactional)

Aggregations

Message (com.axelor.apps.message.db.Message)54 AxelorException (com.axelor.exception.AxelorException)25 MessageServiceBaseImpl (com.axelor.apps.base.service.message.MessageServiceBaseImpl)16 IExceptionMessage (com.axelor.apps.message.exception.IExceptionMessage)14 Transactional (com.google.inject.persist.Transactional)13 IExceptionMessage (com.axelor.apps.hr.exception.IExceptionMessage)11 Template (com.axelor.apps.message.db.Template)7 Timesheet (com.axelor.apps.hr.db.Timesheet)6 ArrayList (java.util.ArrayList)6 Employee (com.axelor.apps.hr.db.Employee)5 EmailAddress (com.axelor.apps.message.db.EmailAddress)5 IExceptionMessage (com.axelor.apps.base.exceptions.IExceptionMessage)4 Expense (com.axelor.apps.hr.db.Expense)4 ExtraHours (com.axelor.apps.hr.db.ExtraHours)4 LeaveRequest (com.axelor.apps.hr.db.LeaveRequest)4 ExpenseService (com.axelor.apps.hr.service.expense.ExpenseService)4 ExtraHoursService (com.axelor.apps.hr.service.extra.hours.ExtraHoursService)4 LeaveService (com.axelor.apps.hr.service.leave.LeaveService)4 TimesheetService (com.axelor.apps.hr.service.timesheet.TimesheetService)4 User (com.axelor.auth.db.User)4