Skip to content

Commit c7803e1

Browse files
committed
fixed extractEmail
1 parent 8e23769 commit c7803e1

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

logicaldoc-webapp/src/main/java/com/logicaldoc/web/service/DocumentServiceImpl.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,8 @@ public GUIDocument getDocument(Session session, long docId)
756756

757757
if (session != null && folder != null) {
758758
FolderDAO fdao = (FolderDAO) Context.get().getBean(FolderDAO.class);
759-
Set<Permission> permissions = fdao.getEnabledPermissions(document.getFolder().getId(), session.getUserId());
759+
Set<Permission> permissions = fdao.getEnabledPermissions(document.getFolder().getId(),
760+
session.getUserId());
760761
List<String> permissionsList = new ArrayList<>();
761762
for (Permission permission : permissions)
762763
permissionsList.add(permission.toString());
@@ -2656,17 +2657,25 @@ public GUIDocument convert(long docId, String fileVersion, String format) throws
26562657
public GUIEmail extractEmail(long docId, String fileVersion) throws ServerException {
26572658
Session session = validateSession();
26582659

2659-
GUIDocument emailDocument = getById(docId);
2660-
if (!emailDocument.getFileName().toLowerCase().endsWith(".eml")
2661-
&& !emailDocument.getFileName().toLowerCase().endsWith(".msg"))
2662-
throw new ServerException("Not an email file");
2660+
DocumentDAO dao = (DocumentDAO) Context.get().getBean(DocumentDAO.class);
2661+
Document emailDocument = null;
2662+
try {
2663+
emailDocument = dao.findDocument(docId);
2664+
if (!emailDocument.getFileName().toLowerCase().endsWith(".eml")
2665+
&& !emailDocument.getFileName().toLowerCase().endsWith(".msg"))
2666+
throw new ServerException("Not an email file");
2667+
} catch (PersistenceException e1) {
2668+
return (GUIEmail) throwServerException(session, log, e1);
2669+
}
26632670

26642671
Storer storer = (Storer) Context.get().getBean(Storer.class);
26652672
String resource = storer.getResourceName(docId, fileVersion, null);
2666-
2673+
2674+
GUIDocument guiDocument = getById(docId);
2675+
26672676
try (InputStream is = storer.getStream(emailDocument.getId(), resource)) {
26682677
GUIEmail guiMail = new GUIEmail();
2669-
EMail email = readEmail(is, docId, emailDocument);
2678+
EMail email = readEmail(is, emailDocument.getId(), guiDocument);
26702679
if (email != null) {
26712680
if (email.getFrom() != null)
26722681
guiMail.setFrom(new GUIContact(email.getFrom().getName(), null, email.getFrom().getAddress()));
@@ -2681,7 +2690,7 @@ public GUIEmail extractEmail(long docId, String fileVersion) throws ServerExcept
26812690

26822691
setEmailRecipients(email, guiMail);
26832692

2684-
setEmailAttachments(emailDocument, email, guiMail);
2693+
setEmailAttachments(guiDocument, email, guiMail);
26852694
}
26862695
return guiMail;
26872696
} catch (IOException e1) {

0 commit comments

Comments
 (0)