"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/main/java/com/openkm/util/MailUtils.java" between
OpenKM-document-management-system-6.3.10.tar.gz and OpenKM-document-management-system-6.3.11.tar.gz

About: OpenKM (Knowledge Management) is a document management system that allows easy management of documents, users, roles and finding your enterprise documents and records. Community version (source code).

MailUtils.java  (OpenKM-document-management-system-6.3.10):MailUtils.java  (OpenKM-document-management-system-6.3.11)
skipping to change at line 105 skipping to change at line 105
* Send mail without FROM addresses. * Send mail without FROM addresses.
* *
* @param toAddress Destination addresses. * @param toAddress Destination addresses.
* @param subject The mail subject. * @param subject The mail subject.
* @param content The mail body. * @param content The mail body.
* @throws MessagingException If there is any error. * @throws MessagingException If there is any error.
*/ */
public static void sendMessage(Collection<String> toAddress, String subje ct, String content) throws MessagingException { public static void sendMessage(Collection<String> toAddress, String subje ct, String content) throws MessagingException {
try { try {
send(null, toAddress, subject, content, new ArrayList<>() ); send(null, toAddress, subject, content, new ArrayList<>() );
} catch (PathNotFoundException | AccessDeniedException | Reposito ryException | IOException | DatabaseException e) { } catch (PathNotFoundException | AccessDeniedException | Reposito ryException | IOException | DatabaseException | LockException e) {
log.warn(e.getMessage(), e); log.warn(e.getMessage(), e);
} }
} }
/** /**
* Send mail without FROM addresses. * Send mail without FROM addresses.
* *
* @param toAddress Destination addresses. * @param toAddress Destination addresses.
* @param subject The mail subject. * @param subject The mail subject.
* @param content The mail body. * @param content The mail body.
* @throws MessagingException If there is any error. * @throws MessagingException If there is any error.
*/ */
public static void sendMessage(String toAddress, String subject, String c ontent) throws MessagingException { public static void sendMessage(String toAddress, String subject, String c ontent) throws MessagingException {
try { try {
ArrayList<String> toList = new ArrayList<>(); ArrayList<String> toList = new ArrayList<>();
toList.add(toAddress); toList.add(toAddress);
send(null, toList, subject, content, new ArrayList<>()); send(null, toList, subject, content, new ArrayList<>());
} catch (PathNotFoundException | AccessDeniedException | Reposito ryException | IOException | DatabaseException e) { } catch (PathNotFoundException | AccessDeniedException | Reposito ryException | IOException | DatabaseException | LockException e) {
log.warn(e.getMessage(), e); log.warn(e.getMessage(), e);
} }
} }
/** /**
* Send mail without FROM addresses. * Send mail without FROM addresses.
* *
* @param toAddress Destination addresses. * @param toAddress Destination addresses.
* @param subject The mail subject. * @param subject The mail subject.
* @param content The mail body. * @param content The mail body.
* @throws MessagingException If there is any error. * @throws MessagingException If there is any error.
*/ */
public static void sendMessage(String fromAddress, List<String> toAddress , String subject, String content) throws MessagingException { public static void sendMessage(String fromAddress, List<String> toAddress , String subject, String content) throws MessagingException {
try { try {
send(fromAddress, toAddress, subject, content, new ArrayL ist<>()); send(fromAddress, toAddress, subject, content, new ArrayL ist<>());
} catch (PathNotFoundException | AccessDeniedException | Reposito ryException | IOException | DatabaseException e) { } catch (PathNotFoundException | AccessDeniedException | Reposito ryException | IOException | DatabaseException | LockException e) {
log.warn(e.getMessage(), e); log.warn(e.getMessage(), e);
} }
} }
/** /**
* Send mail without FROM addresses. * Send mail without FROM addresses.
* *
* @param toAddress Destination addresses. * @param toAddress Destination addresses.
* @param subject The mail subject. * @param subject The mail subject.
* @param content The mail body. * @param content The mail body.
* @throws MessagingException If there is any error. * @throws MessagingException If there is any error.
*/ */
public static void sendMessage(String fromAddress, String toAddress, Stri ng subject, String content) throws MessagingException { public static void sendMessage(String fromAddress, String toAddress, Stri ng subject, String content) throws MessagingException {
try { try {
ArrayList<String> toList = new ArrayList<>(); ArrayList<String> toList = new ArrayList<>();
toList.add(toAddress); toList.add(toAddress);
send(fromAddress, toList, subject, content, new ArrayList <>()); send(fromAddress, toList, subject, content, new ArrayList <>());
} catch (PathNotFoundException | AccessDeniedException | Reposito ryException | IOException | DatabaseException e) { } catch (PathNotFoundException | AccessDeniedException | Reposito ryException | IOException | DatabaseException | LockException e) {
log.warn(e.getMessage(), e); log.warn(e.getMessage(), e);
} }
} }
/** /**
* Send document to non-registered OpenKM users * Send document to non-registered OpenKM users
* *
* @param toAddress Destination addresses. * @param toAddress Destination addresses.
* @param subject The mail subject. * @param subject The mail subject.
* @param text The mail body. * @param text The mail body.
* @throws MessagingException If there is any error. * @throws MessagingException If there is any error.
*/ */
public static void sendDocument(String fromAddress, List<String> toAddres public static void sendDocument(String fromAddress, List<String> toAddress,
s, String subject, String text, String docPath) String subject, String text, String docPath)
throws MessagingException, PathNotFoundException, AccessD throws MessagingException, PathNotFoundException, AccessDeniedExcept
eniedException, RepositoryException, IOException, DatabaseException { ion, RepositoryException, IOException,
DatabaseException, LockException {
send(fromAddress, toAddress, subject, text, Collections.singleton List(docPath)); send(fromAddress, toAddress, subject, text, Collections.singleton List(docPath));
} }
/** /**
* Send document to non-registered OpenKM users * Send document to non-registered OpenKM users
* *
* @param toAddress Destination addresses. * @param toAddress Destination addresses.
* @param subject The mail subject. * @param subject The mail subject.
* @param text The mail body. * @param text The mail body.
* @throws MessagingException If there is any error. * @throws MessagingException If there is any error.
*/ */
public static void sendDocuments(String fromAddress, List<String> toAddre public static void sendDocuments(String fromAddress, List<String> toAddress,
ss, String subject, String text, List<String> docsPath) String subject, String text,
throws MessagingException, PathNotFoundException, AccessD List<String> docsPath) throws MessagingException, PathNotFoundExcept
eniedException, RepositoryException, IOException, DatabaseException { ion, AccessDeniedException, RepositoryException,
IOException, DatabaseException, LockException {
send(fromAddress, toAddress, subject, text, docsPath); send(fromAddress, toAddress, subject, text, docsPath);
} }
/** /**
* Send mail with FROM addresses. * Send mail with FROM addresses.
* *
* @param fromAddress Origin address. * @param fromAddress Origin address.
* @param toAddress Destination addresses. * @param toAddress Destination addresses.
* @param subject The mail subject. * @param subject The mail subject.
* @param text The mail body. * @param text The mail body.
* @throws MessagingException If there is any error. * @throws MessagingException If there is any error.
*/ */
private static void send(String fromAddress, Collection<String> toAddress private static void send(String fromAddress, Collection<String> toAddress, S
, String subject, String text, Collection<String> docsPath) tring subject, String text,
throws MessagingException, PathNotFoundException, AccessD Collection<String> docsPath) throws MessagingException, PathNotFound
eniedException, RepositoryException, IOException, DatabaseException { Exception, AccessDeniedException,
RepositoryException, IOException, DatabaseException, LockException {
log.debug("send({}, {}, {}, {}, {})", fromAddress, toAddress, sub ject, text, docsPath); log.debug("send({}, {}, {}, {}, {})", fromAddress, toAddress, sub ject, text, docsPath);
List<File> tmpAttachments = new ArrayList<>(); List<File> tmpAttachments = new ArrayList<>();
try { try {
// Need a temporal file for every attachment. // Need a temporal file for every attachment.
for (int i = 0; i < docsPath.size(); i++) { for (int i = 0; i < docsPath.size(); i++) {
tmpAttachments.add(FileUtils.createTempFile()); tmpAttachments.add(FileUtils.createTempFile());
} }
MimeMessage m = create(fromAddress, toAddress, subject, t ext, docsPath, tmpAttachments); MimeMessage m = create(fromAddress, toAddress, subject, t ext, docsPath, tmpAttachments);
skipping to change at line 230 skipping to change at line 233
* Forward a mail in the repository. * Forward a mail in the repository.
* *
* @param token Authentication token. * @param token Authentication token.
* @param fromAddress Origin address. * @param fromAddress Origin address.
* @param toAddress Destination addresses. * @param toAddress Destination addresses.
* @param mailPath Path of the mail to be forwarded. * @param mailPath Path of the mail to be forwarded.
* @throws MessagingException If there is any error. * @throws MessagingException If there is any error.
*/ */
public static void forwardMail(String token, String fromAddress, String t oAddress, String message, String mailPath) public static void forwardMail(String token, String fromAddress, String t oAddress, String message, String mailPath)
throws MessagingException, PathNotFoundException, AccessD eniedException, RepositoryException, IOException, throws MessagingException, PathNotFoundException, AccessD eniedException, RepositoryException, IOException,
DatabaseException { DatabaseException, LockException {
ArrayList<String> toList = new ArrayList<>(); ArrayList<String> toList = new ArrayList<>();
toList.add(toAddress); toList.add(toAddress);
forwardMail(token, fromAddress, toList, message, mailPath); forwardMail(token, fromAddress, toList, message, mailPath);
} }
/** /**
* Forward a mail in the repository. * Forward a mail in the repository.
* *
* @param token Authentication token. * @param token Authentication token.
* @param fromAddress Origin address. * @param fromAddress Origin address.
* @param toAddress Destination addresses. * @param toAddress Destination addresses.
* @param mailId Path of the mail to be forwarded or its UUID. * @param mailId Path of the mail to be forwarded or its UUID.
* @throws MessagingException If there is any error. * @throws MessagingException If there is any error.
*/ */
public static void forwardMail(String token, String fromAddress, Collecti public static void forwardMail(String token, String fromAddress, Collection<
on<String> toAddress, String message, String mailId) String> toAddress, String message,
throws MessagingException, PathNotFoundException, AccessD String mailId) throws MessagingException, PathNotFoundException, Acc
eniedException, RepositoryException, IOException, DatabaseException { essDeniedException, RepositoryException,
IOException, DatabaseException, LockException {
log.debug("forwardMail({}, {}, {}, {})", token, fromAddress, toAd dress, mailId); log.debug("forwardMail({}, {}, {}, {})", token, fromAddress, toAd dress, mailId);
Mail mail = OKMMail.getInstance().getProperties(token, mailId); Mail mail = OKMMail.getInstance().getProperties(token, mailId);
mail.setSubject("Fwd: " + mail.getSubject()); mail.setSubject("Fwd: " + mail.getSubject());
if (Mail.MIME_TEXT.equals(mail.getMimeType())) { if (Mail.MIME_TEXT.equals(mail.getMimeType())) {
mail.setContent(message + "\n\n---------- Forwarded messa ge ----------\n\n" + mail.getContent()); mail.setContent(message + "\n\n---------- Forwarded messa ge ----------\n\n" + mail.getContent());
} else if (Mail.MIME_HTML.equals(mail.getMimeType())) { } else if (Mail.MIME_HTML.equals(mail.getMimeType())) {
mail.setContent(message + "<br/><br/>---------- Forwarded message ----------<br/><br/>" + mail.getContent()); mail.setContent(message + "<br/><br/>---------- Forwarded message ----------<br/><br/>" + mail.getContent());
} else { } else {
log.warn("Email does not specify content MIME type"); log.warn("Email does not specify content MIME type");
skipping to change at line 284 skipping to change at line 288
* Create a mail. * Create a mail.
* *
* @param fromAddress Origin address. * @param fromAddress Origin address.
* @param toAddress Destination addresses. * @param toAddress Destination addresses.
* @param subject The mail subject. * @param subject The mail subject.
* @param text The mail body. * @param text The mail body.
* @throws MessagingException If there is any error. * @throws MessagingException If there is any error.
*/ */
private static MimeMessage create(String fromAddress, Collection<String> toAddress, String subject, String text, private static MimeMessage create(String fromAddress, Collection<String> toAddress, String subject, String text,
Collection<String> docsPath, List<File> tmpAttachments) t hrows MessagingException, PathNotFoundException, Collection<String> docsPath, List<File> tmpAttachments) t hrows MessagingException, PathNotFoundException,
AccessDeniedException, RepositoryException, IOException, DatabaseException { AccessDeniedException, RepositoryException, IOException, DatabaseException, LockException {
log.debug("create({}, {}, {}, {}, {})", fromAddress, toAddress, s ubject, text, docsPath); log.debug("create({}, {}, {}, {}, {})", fromAddress, toAddress, s ubject, text, docsPath);
Session mailSession = getMailSession(); Session mailSession = getMailSession();
MimeMessage msg = new MimeMessage(mailSession); MimeMessage msg = new MimeMessage(mailSession);
if (fromAddress != null && Config.SEND_MAIL_FROM_USER) { if (fromAddress != null && Config.SEND_MAIL_FROM_USER) {
InternetAddress from = new InternetAddress(fromAddress); InternetAddress from = new InternetAddress(fromAddress);
msg.setFrom(from); msg.setFrom(from);
} else { } else {
msg.setFrom(); msg.setFrom();
} }
skipping to change at line 372 skipping to change at line 376
msg.saveChanges(); msg.saveChanges();
log.debug("create: {}", msg); log.debug("create: {}", msg);
return msg; return msg;
} }
/** /**
* Create a mail from a Mail object * Create a mail from a Mail object
*/ */
public static MimeMessage create(String token, Mail mail) throws Messagin gException, PathNotFoundException, public static MimeMessage create(String token, Mail mail) throws Messagin gException, PathNotFoundException,
AccessDeniedException, RepositoryException, IOException, DatabaseException { AccessDeniedException, RepositoryException, IOException, DatabaseException, LockException {
log.debug("create({})", mail); log.debug("create({})", mail);
Session mailSession = getMailSession(); Session mailSession = getMailSession();
MimeMessage msg = new MimeMessage(mailSession); MimeMessage msg = new MimeMessage(mailSession);
if (mail.getFrom() != null) { if (mail.getFrom() != null) {
InternetAddress from = new InternetAddress(mail.getFrom() ); InternetAddress from = new InternetAddress(mail.getFrom() );
msg.setFrom(from); msg.setFrom(from);
} else { } else {
msg.setFrom(); msg.setFrom();
} }
skipping to change at line 585 skipping to change at line 589
/** /**
* Import helper. * Import helper.
*/ */
private static String importMessages(String token, Message[] messages, Fo lder folder, MailAccount ma) private static String importMessages(String token, Message[] messages, Fo lder folder, MailAccount ma)
throws MessagingException, DatabaseException { throws MessagingException, DatabaseException {
String exceptionMessage = null; String exceptionMessage = null;
for (int i = 0; i < messages.length; i++) { for (int i = 0; i < messages.length; i++) {
Message msg = messages[i]; Message msg = messages[i];
boolean isSeen = msg.isSet(Flags.Flag.SEEN);
log.info("======= ======= {} ======= =======", i); log.info("======= ======= {} ======= =======", i);
log.info("Folder: {}", folder); log.info("Folder: {}", folder);
log.info("Subject: {}", msg.getSubject()); log.info("Subject: {}", msg.getSubject());
log.info("From: {}", msg.getFrom()); log.info("From: {}", msg.getFrom());
log.info("Received: {}", msg.getReceivedDate()); log.info("Received: {}", msg.getReceivedDate());
log.info("Sent: {}", msg.getSentDate()); log.info("Sent: {}", msg.getSentDate());
try { try {
com.openkm.bean.Mail mail = messageToMail(msg); com.openkm.bean.Mail mail = messageToMail(msg);
skipping to change at line 619 skipping to change at line 624
String mailPath = mf.getP ath(); String mailPath = mf.getP ath();
importMail(token, mailPat h, mf.isGrouping(), folder, msg, ma, mail); importMail(token, mailPat h, mf.isGrouping(), folder, msg, ma, mail);
} }
} }
} }
// Set message as seen // Set message as seen
if (ma.isMailMarkSeen()) { if (ma.isMailMarkSeen()) {
msg.setFlag(Flags.Flag.SEEN, true); msg.setFlag(Flags.Flag.SEEN, true);
} else { } else {
msg.setFlag(Flags.Flag.SEEN, false); msg.setFlag(Flags.Flag.SEEN, isSeen);
} }
// Delete read mail if requested // Delete read mail if requested
if (ma.isMailMarkDeleted()) { if (ma.isMailMarkDeleted()) {
msg.setFlag(Flags.Flag.DELETED, true); msg.setFlag(Flags.Flag.DELETED, true);
} }
// Set lastUid // Set lastUid
if (folder instanceof IMAPFolder) { if (folder instanceof IMAPFolder) {
long msgUid = ((IMAPFolder) folder).getUI D(msg); long msgUid = ((IMAPFolder) folder).getUI D(msg);
 End of changes. 13 change blocks. 
24 lines changed or deleted 29 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)