Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update chinese translation 、 encode download non english filename、 email sender will be owner of attached file、 fix email wrong workflow link #773

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions docs-core/src/main/java/com/sismics/docs/core/dao/UserDao.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package com.sismics.docs.core.dao;

import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import at.favre.lib.crypto.bcrypt.BCrypt;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import com.sismics.docs.core.constant.AuditLogType;
import com.sismics.docs.core.constant.Constants;
import com.sismics.docs.core.dao.criteria.UserCriteria;
Expand All @@ -19,11 +26,10 @@
import com.sismics.docs.core.util.jpa.SortCriteria;
import com.sismics.util.context.ThreadLocalContext;

import at.favre.lib.crypto.bcrypt.BCrypt;
import jakarta.persistence.EntityManager;
import jakarta.persistence.NoResultException;
import jakarta.persistence.Query;
import java.sql.Timestamp;
import java.util.*;

/**
* User DAO.
Expand Down Expand Up @@ -233,6 +239,23 @@ public User getActiveByUsername(String username) {
return null;
}
}

/**
* Gets an active user by its email.
*
* @param email User's email
* @return User
*/
public User getByEmail(String email) {
EntityManager em = ThreadLocalContext.get().getEntityManager();
try {
Query q = em.createQuery("select u from User u where u.email = :email and u.deleteDate is null");
q.setParameter("email", email);
return (User) q.getSingleResult();
} catch (NoResultException e) {
return null;
}
}

/**
* Deletes a user.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
package com.sismics.docs.core.service;

import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.FolderClosedException;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.internet.InternetAddress;
import javax.mail.search.FlagTerm;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.util.concurrent.AbstractScheduledService;
import com.sismics.docs.core.constant.ConfigType;
import com.sismics.docs.core.dao.TagDao;
import com.sismics.docs.core.dao.UserDao;
import com.sismics.docs.core.dao.criteria.TagCriteria;
import com.sismics.docs.core.dao.dto.TagDto;
import com.sismics.docs.core.event.DocumentCreatedAsyncEvent;
Expand All @@ -15,16 +39,6 @@
import com.sismics.docs.core.util.jpa.SortCriteria;
import com.sismics.util.EmailUtil;
import com.sismics.util.context.ThreadLocalContext;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.mail.*;
import javax.mail.search.FlagTerm;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Inbox scanning service.
Expand Down Expand Up @@ -88,7 +102,8 @@ public void syncInbox() {
Message[] messages = inbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
log.info(messages.length + " messages found");
for (Message message : messages) {
importMessage(message, tagsNameToId);
InternetAddress sender = (InternetAddress) message.getFrom()[0];
importMessage(message, tagsNameToId,sender);
lastSyncMessageCount++;
}
} catch (FolderClosedException e) {
Expand Down Expand Up @@ -190,8 +205,8 @@ private Folder openInbox() throws Exception {
* @param message Message
* @throws Exception e
*/
private void importMessage(Message message, Map<String, String> tags) throws Exception {
log.info("Importing message: " + message.getSubject());
private void importMessage(Message message, Map<String, String> tags,InternetAddress sender) throws Exception {
log.info("Importing message: " + message.getSubject()+",sender="+sender.getAddress());

// Parse the mail
EmailUtil.MailContent mailContent = new EmailUtil.MailContent();
Expand Down Expand Up @@ -219,8 +234,12 @@ private void importMessage(Message message, Map<String, String> tags) throws Exc
log.debug("Tags found: " + String.join(", ", tagsFound));
subject = subject.trim().replaceAll(" +", " ");
}

document.setUserId("admin");
UserDao userDao = new UserDao();
com.sismics.docs.core.model.jpa.User user = userDao.getByEmail(sender.getAddress());
if(user!=null)
document.setUserId(user.getId());
else
document.setUserId("admin");
document.setTitle(StringUtils.abbreviate(subject, 100));
document.setDescription(StringUtils.abbreviate(mailContent.getMessage(), 4000));
document.setSubject(StringUtils.abbreviate(mailContent.getSubject(), 500));
Expand All @@ -232,9 +251,13 @@ private void importMessage(Message message, Map<String, String> tags) throws Exc
} else {
document.setCreateDate(mailContent.getDate());
}
if(user!=null)
DocumentUtil.createDocument(document, user.getId());
else{
// Save the document, create the base ACLs
DocumentUtil.createDocument(document, "admin");
}

// Save the document, create the base ACLs
DocumentUtil.createDocument(document, "admin");

// Add the tag
String tagId = ConfigUtil.getConfigStringValue(ConfigType.INBOX_TAG);
Expand All @@ -253,12 +276,19 @@ private void importMessage(Message message, Map<String, String> tags) throws Exc

// Raise a document created event
DocumentCreatedAsyncEvent documentCreatedAsyncEvent = new DocumentCreatedAsyncEvent();
documentCreatedAsyncEvent.setUserId("admin");
if(user!=null)
documentCreatedAsyncEvent.setUserId(user.getId());
else
documentCreatedAsyncEvent.setUserId("admin");
documentCreatedAsyncEvent.setDocumentId(document.getId());
ThreadLocalContext.get().addAsyncEvent(documentCreatedAsyncEvent);

// Add files to the document
for (EmailUtil.FileContent fileContent : mailContent.getFileContentList()) {
if(user!=null)
FileUtil.createFile(fileContent.getName(), null, fileContent.getFile(), fileContent.getSize(),
document.getLanguage(), user.getId(), document.getId());
else
FileUtil.createFile(fileContent.getName(), null, fileContent.getFile(), fileContent.getSize(),
document.getLanguage(), "admin", document.getId());
}
Expand Down
2 changes: 1 addition & 1 deletion docs-core/src/main/resources/db/update/dbupdate-006-0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ insert into T_VOCABULARY(VOC_ID_C, VOC_NAME_C, VOC_VALUE_C, VOC_ORDER_N) values(
insert into T_VOCABULARY(VOC_ID_C, VOC_NAME_C, VOC_VALUE_C, VOC_ORDER_N) values('coverage-swe', 'coverage', 'Sweden', 214);
insert into T_VOCABULARY(VOC_ID_C, VOC_NAME_C, VOC_VALUE_C, VOC_ORDER_N) values('coverage-che', 'coverage', 'Switzerland', 215);
insert into T_VOCABULARY(VOC_ID_C, VOC_NAME_C, VOC_VALUE_C, VOC_ORDER_N) values('coverage-syr', 'coverage', 'Syrian Arab Republic', 216);
insert into T_VOCABULARY(VOC_ID_C, VOC_NAME_C, VOC_VALUE_C, VOC_ORDER_N) values('coverage-twn', 'coverage', 'Taiwan, Province of China', 217);
insert into T_VOCABULARY(VOC_ID_C, VOC_NAME_C, VOC_VALUE_C, VOC_ORDER_N) values('coverage-twn', 'coverage', 'Taiwan', 217);
insert into T_VOCABULARY(VOC_ID_C, VOC_NAME_C, VOC_VALUE_C, VOC_ORDER_N) values('coverage-tjk', 'coverage', 'Tajikistan', 218);
insert into T_VOCABULARY(VOC_ID_C, VOC_NAME_C, VOC_VALUE_C, VOC_ORDER_N) values('coverage-tza', 'coverage', 'Tanzania, United Republic of', 219);
insert into T_VOCABULARY(VOC_ID_C, VOC_NAME_C, VOC_VALUE_C, VOC_ORDER_N) values('coverage-tha', 'coverage', 'Thailand', 220);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
<p>${messages('email.template.route_step_validate.hello', user_name)}</p>
<p>${messages['email.template.route_step_validate.instruction1']}</p>
<p>${messages['email.template.route_step_validate.instruction2']}</p>
<a href="${base_url}/#/document/${document_id}">${document_title}</a>
<a href="${base_url}/#/document/view/${document_id}/content">${document_title}</a>
</@layout.email>
20 changes: 10 additions & 10 deletions docs-core/src/main/resources/messages_zh_TW.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
email.template.password_recovery.subject=\u8ACB\u91CD\u65B0\u8A2D\u7F6E\u60A8\u7684\u5BC6\u78BC
email.template.password_recovery.hello=\u60A8\u597D{0}\uFF01
email.template.password_recovery.instruction1=\u6211\u5011\u6536\u5230\u4E86\u91CD\u7F6E\u5BC6\u78BC\u7684\u8ACB\u6C42\u3002<br/>\u5982\u679C\u60A8\u6C92\u6709\u8ACB\u6C42\u5E6B\u52A9\uFF0C\u8ACB\u5FFD\u7565\u6B64\u96FB\u5B50\u90F5\u4EF6\u3002
email.template.password_recovery.instruction2=\u8981\u91CD\u7F6E\u60A8\u7684\u5BC6\u78BC\uFF0C\u8ACB\u8A2A\u554F\u4EE5\u4E0B\u93C8\u63A5\uFF1A
email.template.password_recovery.click_here=\u9EDE\u64CA\u9019\u88E1\u91CD\u7F6E\u60A8\u7684\u5BC6\u78BC
email.template.route_step_validate.subject=\u4E00\u4EFD\u6587\u4EF6\u9700\u8981\u4F60\u7684\u95DC\u6CE8
email.template.route_step_validate.hello={0}\uFF0C\u60A8\u597D.
email.template.route_step_validate.instruction1=\u5DE5\u4F5C\u6D41\u6B65\u9A5F\u5DF2\u7D93\u5206\u914D\u7D66\u60A8\uFF0C\u9700\u8981\u60A8\u7684\u95DC\u6CE8\u3002
email.template.route_step_validate.instruction2=\u8981\u67E5\u770B\u6587\u6A94\u4E26\u9A57\u8B49\u5DE5\u4F5C\u6D41\u7A0B\uFF0C\u8ACB\u8A2A\u554F\u4EE5\u4E0B\u93C8\u63A5\uFF1A
email.no_html.error=\u60A8\u7684\u96FB\u5B50\u90F5\u4EF6\u5BA2\u6236\u7AEF\u4E0D\u652F\u6301HTML\u683C\u5F0F\u90F5\u4EF6
email.template.password_recovery.subject=\u8acb\u91cd\u65b0\u8a2d\u7f6e\u60a8\u7684\u5bc6\u78bc
email.template.password_recovery.hello=\u60a8\u597d{0}\uff01
email.template.password_recovery.instruction1=\u6211\u5011\u6536\u5230\u91cd\u7f6e\u5bc6\u78bc\u7684\u8981\u6c42\u3002<br/>\u5982\u679c\u60a8\u6c92\u6709\u8981\u6c42\u5354\u52a9\uff0c\u8acb\u5ffd\u7565\u6b64\u96fb\u5b50\u90f5\u4ef6\u3002
email.template.password_recovery.instruction2=\u8981\u91cd\u7f6e\u60a8\u7684\u5bc6\u78bc\uff0c\u8acb\u8a2a\u554f\u4ee5\u4e0b\u9023\u7d50\uff1a
email.template.password_recovery.click_here=\u9ede\u64ca\u9019\u88e1\u91cd\u7f6e\u60a8\u7684\u5bc6\u78bc
email.template.route_step_validate.subject=\u4e00\u4efd\u6587\u4ef6\u9700\u8981\u4f60\u7684\u95dc\u6ce8
email.template.route_step_validate.hello={0}\uff0c\u60a8\u597d.
email.template.route_step_validate.instruction1=\u5de5\u4f5c\u6d41\u7a0b\u5df2\u7d93\u5206\u914d\u7d66\u60a8\uff0c\u9700\u8981\u60a8\u7684\u95dc\u6ce8\u3002
email.template.route_step_validate.instruction2=\u8981\u67e5\u770b\u6587\u6a94\u4e26\u5be9\u6838\u5de5\u4f5c\u6d41\u7a0b\uff0c\u8acb\u8a2a\u554f\u4ee5\u4e0b\u9023\u7d50\uff1a
email.no_html.error=\u60a8\u7684\u96fb\u5b50\u90f5\u4ef6\u5ba2\u6236\u7aef\u7a0b\u5f0f\u4e0d\u652f\u63f4HTML\u683c\u5f0f\u90f5\u4ef6
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
package com.sismics.docs.rest.resource;

import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.text.MessageFormat;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.glassfish.jersey.media.multipart.FormDataParam;

import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.io.ByteStreams;
Expand Down Expand Up @@ -27,30 +43,27 @@
import com.sismics.util.JsonUtil;
import com.sismics.util.context.ThreadLocalContext;
import com.sismics.util.mime.MimeType;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.glassfish.jersey.media.multipart.FormDataParam;

import jakarta.json.Json;
import jakarta.json.JsonArrayBuilder;
import jakarta.json.JsonObjectBuilder;
import jakarta.ws.rs.*;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.FormParam;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.NotFoundException;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
import jakarta.ws.rs.core.StreamingOutput;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.text.MessageFormat;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
* File REST resources.
Expand Down Expand Up @@ -637,7 +650,7 @@ public Response data(
}

Response.ResponseBuilder builder = Response.ok(stream)
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + file.getFullName("data") + "\"")
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename*=utf-8''" + filenameEncode( file.getFullName("data") ))
.header(HttpHeaders.CONTENT_TYPE, mimeType);
if (decrypt) {
// Cache real files
Expand All @@ -651,6 +664,15 @@ public Response data(
return builder.build();
}

private String filenameEncode(String name) {
try {
return java.net.URLEncoder.encode(name, "UTF-8").replace("+", "%20");
} catch (java.io.UnsupportedEncodingException e) {
e.printStackTrace();
return name;
}
}

/**
* Returns all files from a document, zipped.
*
Expand Down
Loading