use of javax.mail.internet.MimeMessage in project webofneeds by researchstudio-sat.
the class MailFileNeedProducer method readNeedFromFile.
@Override
public synchronized Dataset readNeedFromFile(final File file) throws IOException {
logger.debug("processing as mail file: {} ", file);
FileInputStream fis = new FileInputStream(file);
DefaultNeedModelWrapper needModelWrapper = new DefaultNeedModelWrapper("no:uri");
try {
MimeMessage emailMessage = new MimeMessage(null, fis);
MimeMessageParser parser = new MimeMessageParser(emailMessage);
parser.parse();
needModelWrapper.setTitle(needContentPropertyType, parser.getSubject());
String content = null;
if (parser.hasPlainContent()) {
content = parser.getPlainContent();
} else if (parser.hasHtmlContent()) {
Document doc = Jsoup.parse(parser.getHtmlContent());
content = doc.text();
}
if (content != null) {
needModelWrapper.setDescription(needContentPropertyType, content);
}
logger.debug("mail subject : {}", parser.getSubject());
logger.debug("mail has plain content: {}", parser.hasPlainContent());
logger.debug("mail has html content : {}", parser.hasHtmlContent());
logger.debug("mail has attachments : {}", parser.hasAttachments());
logger.debug("mail plain content : {}", StringUtils.abbreviate(parser.getPlainContent(), 200));
logger.debug("mail html content : {}", StringUtils.abbreviate(parser.getHtmlContent(), 200));
return needModelWrapper.copyDataset();
} catch (Exception e) {
logger.error("could not parse email from file {} ", file, e);
} finally {
if (fis != null)
fis.close();
}
return null;
}
use of javax.mail.internet.MimeMessage in project webofneeds by researchstudio-sat.
the class MailCommandAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
EventListenerContext ctx = getEventListenerContext();
if (event instanceof MailCommandEvent && ctx.getBotContextWrapper() instanceof MailBotContextWrapper) {
MailBotContextWrapper botContextWrapper = (MailBotContextWrapper) ctx.getBotContextWrapper();
MimeMessage message = ((MailCommandEvent) event).getMessage();
String referenceId = MailContentExtractor.getMailReference(message);
WonURI wonUri = botContextWrapper.getWonURIForMailId(referenceId);
// determine if the mail is referring to some other mail/need/connection or not
if (wonUri != null) {
processReferenceMailCommands(message, wonUri);
} else {
processNonReferenceMailCommand(message);
}
}
}
use of javax.mail.internet.MimeMessage in project webofneeds by researchstudio-sat.
the class SubscribeUnsubscribeAction method doRun.
@Override
protected void doRun(final Event event, EventListener executingListener) throws Exception {
EventListenerContext ctx = getEventListenerContext();
if (event instanceof SubscribeUnsubscribeEvent && ctx.getBotContextWrapper() instanceof MailBotContextWrapper) {
MailBotContextWrapper botContextWrapper = (MailBotContextWrapper) ctx.getBotContextWrapper();
// save the new subscription status of the user to the bot context
SubscribeUnsubscribeEvent subscribeEvent = (SubscribeUnsubscribeEvent) event;
SubscribeStatus subscribeStatus = subscribeEvent.getSubscribeStatus();
String senderMailAddress = MailContentExtractor.getMailSender(subscribeEvent.getMessage());
botContextWrapper.setSubscribeStatusForMailAddress(senderMailAddress, subscribeStatus);
// depending on the new subscribe status of the user publish his cached mails as needs or delete the cache
if (SubscribeStatus.SUBSCRIBED.equals(subscribeStatus)) {
EventBus bus = getEventListenerContext().getEventBus();
Collection<MimeMessage> cachedMessages = botContextWrapper.loadCachedMailsForMailAddress(senderMailAddress);
cachedMessages.stream().forEach(message -> bus.publish(new CreateNeedFromMailEvent(message)));
} else if (SubscribeStatus.UNSUBSCRIBED.equals(subscribeStatus)) {
botContextWrapper.removeCachedMailsForMailAddress(senderMailAddress);
}
}
}
use of javax.mail.internet.MimeMessage in project webofneeds by researchstudio-sat.
the class Connect2MailParserAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
EventListenerContext ctx = getEventListenerContext();
if (event instanceof ConnectFromOtherNeedEvent && ctx.getBotContextWrapper() instanceof MailBotContextWrapper) {
MailBotContextWrapper botContextWrapper = (MailBotContextWrapper) ctx.getBotContextWrapper();
Connection con = ((ConnectFromOtherNeedEvent) event).getCon();
URI responseTo = con.getNeedURI();
URI remoteNeedUri = con.getRemoteNeedURI();
MimeMessage originalMail = botContextWrapper.getMimeMessageForURI(responseTo);
logger.debug("Someone issued a connect for URI: " + responseTo + " sending a mail to the creator: " + MailContentExtractor.getFromAddressString(originalMail));
WonMimeMessage answerMessage = mailGenerator.createConnectMail(originalMail, remoteNeedUri);
botContextWrapper.addMailIdWonURIRelation(answerMessage.getMessageID(), new WonURI(con.getConnectionURI(), UriType.CONNECTION));
sendChannel.send(new GenericMessage<>(answerMessage));
}
}
use of javax.mail.internet.MimeMessage in project webofneeds by researchstudio-sat.
the class Hint2MailParserAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
EventListenerContext ctx = getEventListenerContext();
if (event instanceof HintFromMatcherEvent && ctx.getBotContextWrapper() instanceof MailBotContextWrapper) {
MailBotContextWrapper botContextWrapper = (MailBotContextWrapper) ctx.getBotContextWrapper();
Match match = ((HintFromMatcherEvent) event).getMatch();
WonMessage message = ((HintFromMatcherEvent) event).getWonMessage();
URI responseTo = match.getFromNeed();
URI remoteNeedUri = match.getToNeed();
MimeMessage originalMail = botContextWrapper.getMimeMessageForURI(responseTo);
logger.debug("Found a hint for URI: " + responseTo + " sending a mail to the creator: " + MailContentExtractor.getFromAddressString(originalMail));
WonMimeMessage answerMessage = mailGenerator.createHintMail(originalMail, remoteNeedUri);
botContextWrapper.addMailIdWonURIRelation(answerMessage.getMessageID(), new WonURI(message.getReceiverURI(), UriType.CONNECTION));
sendChannel.send(new GenericMessage<>(answerMessage));
}
}
Aggregations