7cf738d43c5d38e9a6246c7d6212d2d5bd055886..ad7c8d2561e5ee1b35aa289fd3e18fa6b5e42481
2024-09-14 xinyb
CRM邮箱优化调整
ad7c8d 对比 | 目录
2024-09-14 xinyb
CRM邮箱配置和收发功能优化
048b74 对比 | 目录
2024-09-14 xinyb
CRM邮箱发邮件功能优化
f6ae0b 对比 | 目录
13个文件已修改
224 ■■■■■ 已修改文件
src/com/yc/crm/custom/service/CustomImpl.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/action/MailAccount.java 29 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/action/MailController.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/entity/t482101HEntity.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/entity/t482101HList.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/service/MailAccountImpl.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/service/MailBlackListImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/service/MailFolderImpl.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/service/MailImpl.java 69 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/service/MailQuickTextImpl.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/service/MailServiceImpl.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/service/MailSignatureImpl.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/service/MailTagImpl.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/custom/service/CustomImpl.java
@@ -5,6 +5,7 @@
import com.yc.crm.custom.entity.T480601HEntity;
import com.yc.service.BaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@@ -17,7 +18,7 @@
 */
@Service
public class CustomImpl extends BaseService implements CustomIfc {
    @Transactional(rollbackFor = Exception.class)
    @Override
    public String saveCustom(T480601HEntity custom) {
        String sql = "set nocount on\n";
@@ -49,7 +50,7 @@
            throw e;
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateCustom(T480601HEntity custom) {
        String sql = "set nocunt on \n";
@@ -64,7 +65,7 @@
            throw e;
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer deleteCustom(String docCode, String userCode) {
        String sql = "set nocunt on \n";
src/com/yc/crm/mail/action/MailAccount.java
@@ -485,17 +485,30 @@
    private String emailDetection(T482102Entity emailEntity) throws MessagingException {
        String errorMsg = "";
        try {
            String protocol = emailEntity.getReceiveProtocol().toLowerCase();//接收协议 imap pop3
            Properties props = new Properties();
            props.put("mail.store.protocol", protocol);//指定接收的邮件协议 IMAP over pop3
            if (protocol.contains("imap")) {
                props.put("mail.imaps.host", emailEntity.getReceiveHost());
                props.put("mail.imaps.port", emailEntity.getReceivePort());
            } else if (protocol.contains("pop3")) {
                props.put("mail.pop3.host", emailEntity.getReceiveHost());
                props.put("mail.pop3.port", emailEntity.getReceivePort());
            } else {
                props.put("mail.imaps.host", emailEntity.getReceiveHost());
                props.put("mail.imaps.port", emailEntity.getReceivePort());
            }
//            props.put("mail.imap.ssl.enable", emailEntity.isReceiveSSL()+""); // 使用 SSL 连接
//            props.put("mail.imap.starttls.enable", "true");//// IMAP 协议设置 STARTTLS
            props.put("mail.store.protocol", "imaps");//emailEntity.getReceiveProtocol()); // IMAP over SSL
            props.put("mail.imaps.host", emailEntity.getReceiveHost());
            props.put("mail.imaps.port", emailEntity.getReceivePort());
            props.put("mail.imaps.starttls.enable", "true");//// IMAP 协议设置 STARTTLS
            props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.ssl.enable", emailEntity.isSmtpSSL() + "");//启用SSL
            props.put("mail.smtp.host", emailEntity.getSmtpHost()); // 替换为你的SMTP服务器
            props.put("mail.smtp.port", emailEntity.getSmtpPort()); // 或者你使用的端口
            props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.starttls.enable", "true");//启用tls
            props.put("mail.smtp.ssl.enable", emailEntity.isSmtpSSL() + "");//启用SSL
//            props.put("mail.smtp.starttls.enable", "true");//启用tls
//            props.setProperty("mail.smtp.socketFactory.port", "587");//启用tls后port:587
            HashMap IAM = new HashMap();
            //带上IMAP ID信息,由key和value组成,例如name,version,vendor,support-email等。
@@ -513,7 +526,7 @@
            });
            //存储对象
            IMAPStore store = (IMAPStore) session.getStore(emailEntity.getReceiveProtocol());//imap协议或pop3协议类型(推荐你使用IMAP协议来存取服务器上的邮件。)
            IMAPStore store = (IMAPStore) session.getStore(protocol);//imap协议或pop3协议类型(推荐你使用IMAP协议来存取服务器上的邮件。)
            //连接
            store.connect(emailEntity.getReceiveHost(), emailEntity.getReceiveEmail(), emailEntity.getReceivePassword());
            store.id(IAM);//163邮箱需要,不然会报:A3 NO SELECT Unsafe Login. Please contact kefu@188.com for help
src/com/yc/crm/mail/action/MailController.java
@@ -7,6 +7,7 @@
import com.yc.crm.mail.util.AllBackMsg;
import com.yc.entity.AttachmentConfig;
import com.yc.entity.DataSourceEntity;
import com.yc.entity.attachment.AttachmentEntity;
import com.yc.factory.FactoryBean;
import com.yc.multiData.MultiDataSource;
import com.yc.multiData.SpObserver;
@@ -16,6 +17,7 @@
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.*;
import javax.mail.MessagingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@@ -130,12 +132,12 @@
            t482101HEntity t482101HEntity = emailIfc.getReceivingMailInfo(docCode);
            if (t482101HEntity != null) {
                if (StringUtils.isNotBlank(t482101HEntity.getAttachmentList())) {//附件的处理
                    //获取到附件内容
                    List<AttachmentEntity> attachmentEntities = emailIfc.getAttachmentEntityList(t482101HEntity.getAttachmentList());
                    List<String> list = new ArrayList<>();
                    String[] path = t482101HEntity.getAttachmentList().split(";");
                    if (path.length > 1) {
                        String unId = path[0];//第一个必定是unid;
                        for (int p = 1; p < path.length; p++) {
                            list.add(shoppingImageServer + "/uploads/attachment/82/482101/" + unId + "@p@" + path[p]);
                    if (attachmentEntities.size() > 0) {
                        for (AttachmentEntity a : attachmentEntities) {
                            list.add(shoppingImageServer + "/uploads/attachment/"+dataSourceEntity.getDbId()+"/482101/" + a.getUnid() + "@p@" + a.getPhysicalFile());
                        }
                        t482101HEntity.setAttachmentPath(list);
                    }
@@ -342,16 +344,22 @@
            //发送
            mailServiceIfc.sendEmails(t482101H, request);
            msg.setOk("发送成功");
        } catch (Exception e) {
        } catch (MessagingException e) {
            String error = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
            String[] arrayError = error.split("#");
            if (arrayError.length == 2) {
                Map<String, Object> map = new HashMap<>();
                map.put("docCode", arrayError[1]);
                msg.setError(arrayError[0], map);
            if (StringUtils.isNotBlank(error)) {
                String[] arrayError = error.split("#");
                if (arrayError.length == 2) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("docCode", arrayError[1]);
                    msg.setError(arrayError[0], map);
                } else {
                    msg.setFail(error);
                }
            } else {
                msg.setFail(error);
            }
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
src/com/yc/crm/mail/entity/t482101HEntity.java
@@ -19,6 +19,7 @@
    private Integer classType = 0;// [note: '1:客户2:同事3:通讯录0:其他']
    private String docCode;// [primary key ]
    private Integer mailType;// [note: '0:草稿箱1:收件箱2:发件箱']
    private String senderName;//发送人名称
    private String sender;// [note:'发送人']
    private List<String> receiver = new ArrayList<>();// [note:'接收人']
    private Integer folderId = 0;// [note:'文件夹id']
@@ -84,6 +85,8 @@
    private String remark;// [note: '备注']
    private MailFileEntity mailFile = null;//附件的对象
    private String messageId;//邮件唯一Id
    private Integer handle;//是否待处理 1是 0不是
    private String handleTime;//待处理时间
    private Integer docVersion;
}
src/com/yc/crm/mail/entity/t482101HList.java
@@ -19,6 +19,7 @@
    private Integer classType = 0;// [note: '1:客户2:同事3:通讯录0:其他']
    private String docCode;// [primary key ]
    private Integer mailType;// [note: '0:草稿箱1:收件箱2:发件箱']
    private String senderName;//发件人名称
    private String sender;// [note:'发送人']
    private List<String> receiver = new ArrayList<>();
    private Integer folderId = 0;// [note:'文件夹id']
src/com/yc/crm/mail/service/MailAccountImpl.java
@@ -6,6 +6,7 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@@ -18,6 +19,7 @@
 */
@Service
public class MailAccountImpl extends BaseService implements MailAccountIfc {
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void addEmailAccount(T482102Entity account) {
        String sql = "set nocount on\n";
@@ -39,6 +41,7 @@
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateEmailAccount(T482102Entity account) {
        String sql = "set nocount on\n";
@@ -69,6 +72,7 @@
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateEmailTime(Integer accountId) {
        String sql = "set nocount on\n";
@@ -82,6 +86,7 @@
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateMailStatus(String status, Integer accountId) {
        String sql = "set nocount on\n";
@@ -95,6 +100,7 @@
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateAliasEmail(String aliasEmail, Integer accountId) {
        String sql = "set nocount on\n";
@@ -108,6 +114,7 @@
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer deleteEmailAccount(String userCode, Integer accountId) {
        String sql = "set nocount on\n";
src/com/yc/crm/mail/service/MailBlackListImpl.java
@@ -6,6 +6,7 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@@ -18,6 +19,7 @@
 */
@Service
public class MailBlackListImpl extends BaseService implements MailBlackListIfc {
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveBlackList(T482106Entity black) {
        String sql = "set nocount on\n";
@@ -32,6 +34,7 @@
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateBlackList(T482106Entity black) {
        String sql = "set nocount on \n";
@@ -45,6 +48,7 @@
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer deleteBlackList(String userCode,Integer blackId) {
        String sql = "set nocount on \n";
src/com/yc/crm/mail/service/MailFolderImpl.java
@@ -6,6 +6,7 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@@ -18,6 +19,7 @@
 */
@Service
public class MailFolderImpl extends BaseService implements MailFolderIfc {
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveFolder(T482107Entity folder) {
        String sql = "set nocount on\n";
@@ -32,7 +34,7 @@
            throw e;
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateFolder(T482107Entity folder) {
        String sql = "set nocount on\n";
@@ -47,7 +49,7 @@
            throw e;
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer deleteFolder(String userCode, Integer folderId) {
        String sql = "set nocount on\n";
src/com/yc/crm/mail/service/MailImpl.java
@@ -11,11 +11,14 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
@@ -34,6 +37,7 @@
    final static String shoppingImageServer = AttachmentConfig.get("attachment.server");
    @Transactional(rollbackFor = Exception.class)
    @Override
    public t482101HEntity saveReceivingMail(t482101HEntity m) {
        String sql = "set nocount on\n";
@@ -42,13 +46,13 @@
                sql += "declare @docCode varchar(50) ,@unid varchar(50),@fieldId varchar(100),@originalFileName varchar(100)," +
                        "@physicalFile varchar(50),@OriginalPicture varbinary(max) \n";
                sql += "exec sp_newdoccode 482101," + GridUtils.prossSqlParm(m.getUserCode()) + ",@docCode output \n";
                sql += "insert into t482101H(companyId,companyName,formId,docCode,docdate,PeriodID,postCode,postname,mailType,sender,receiver," +
                sql += "insert into t482101H(companyId,companyName,formId,docCode,docdate,PeriodID,postCode,postname,mailType,senderName,sender,receiver," +
                        "cc,bcc,subject,userCode,userName,content,plain_text,messageId,read_flag,delete_flag,create_time,update_time,receive_time," +
                        "attach_flag,attachment_list) values ";
                sql += "(" + GridUtils.prossSqlParm(m.getCompanyId()) + "," + GridUtils.prossSqlParm(m.getCompanyName()) + ",482101," +
                        "@docCode,convert(varchar(10),getdate(),120),convert(varchar(7),getdate(),120),"
                        + GridUtils.prossSqlParm(m.getUserCode()) + "," + GridUtils.prossSqlParm(m.getUserName()) + "," +
                        +m.getMailType() + "," + GridUtils.prossSqlParm(m.getSender()) + "," +
                        +m.getMailType() + "," + GridUtils.prossSqlParm(m.getSenderName()) + "," + GridUtils.prossSqlParm(m.getSender()) + "," +
                        GridUtils.prossSqlParm(StringUtils.join(m.getReceiver(), ",")) + "," + GridUtils.prossSqlParm(StringUtils.join(m.getCc(), ",")) + "," +
                        GridUtils.prossSqlParm(StringUtils.join(m.getBcc(), ",")) + "," +
                        GridUtils.prossSqlParm(m.getSubject()) + "," + GridUtils.prossSqlParm(m.getUserCode()) + "," + GridUtils.prossSqlParm(m.getUserName()) + "," +
@@ -70,6 +74,7 @@
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveReceivingMailList(List<t482101HEntity> mail) {
        String sql = "set nocount on\n";
@@ -78,13 +83,13 @@
                    "@physicalFile varchar(50),@OriginalPicture varbinary(max) \n";
            for (t482101HEntity m : mail) {//遍历内容
                sql += "exec sp_newdoccode 482101," + GridUtils.prossSqlParm(m.getUserCode()) + ",@docCode output \n";
                sql += "insert into t482101H(companyId,companyName,formId,docCode,docdate,PeriodID,postCode,postname,mailType,sender,receiver," +
                sql += "insert into t482101H(companyId,companyName,formId,docCode,docdate,PeriodID,postCode,postname,mailType,senderName,sender,receiver," +
                        "cc,bcc,subject,userCode,userName,content,plain_text,messageId,read_flag,delete_flag,create_time,update_time,receive_time," +
                        "attach_flag,attachment_list) values ";
                sql += "(" + GridUtils.prossSqlParm(m.getCompanyId()) + "," + GridUtils.prossSqlParm(m.getCompanyName()) + ",482101," +
                        "@docCode,convert(varchar(10),getdate(),120),convert(varchar(7),getdate(),120),"
                        + GridUtils.prossSqlParm(m.getUserCode()) + "," + GridUtils.prossSqlParm(m.getUserName()) + "," +
                        +m.getMailType() + "," + GridUtils.prossSqlParm(m.getSender()) + "," +
                        +m.getMailType() + "," + GridUtils.prossSqlParm(m.getSenderName()) + "," + GridUtils.prossSqlParm(m.getSender()) + "," +
                        GridUtils.prossSqlParm(StringUtils.join(m.getReceiver(), ",")) + "," + GridUtils.prossSqlParm(StringUtils.join(m.getCc(), ",")) + "," +
                        GridUtils.prossSqlParm(StringUtils.join(m.getBcc(), ",")) + "," +
                        GridUtils.prossSqlParm(m.getSubject()) + "," + GridUtils.prossSqlParm(m.getUserCode()) + "," + GridUtils.prossSqlParm(m.getUserName()) + "," +
@@ -130,6 +135,7 @@
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateReceivingMail(t482101HEntity mail) {
        String sql = "set nocount on\n";
@@ -146,6 +152,7 @@
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateDeleteFlag(String userCode, String docCode) {
        String sql = "set nocount on\n";
@@ -160,6 +167,7 @@
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer deleteEmail(String userCode, String docCode) {
        String sql = "set nocount on\n";
@@ -191,9 +199,11 @@
    public t482101HEntity getReceivingMailInfo(String docCode) {
        String sql = "set nocount on\n";
        try {
            sql += "select top 1 DocCode,companyId,companyName,sender,receiver,mailType,subject,content,plain_text,file_unid as fileUNID,messageId," +
            sql += "select top 1 DocCode,companyId,companyName,senderName,senderName,sender,receiver,mailType,subject,content,plain_text,file_unid as fileUNID,messageId," +
                    "read_flag,delete_flag,attach_flag,urgent_flag,receipt_flag,track_flag,userCode,userName,create_time,update_time," +
                    "send_status,receive_time,sign_id,attachment_list,remark,remark,DocVersion from t482101H " +
                    "send_status,receive_time,sign_id,attachment_list,remark,remark," +
                    "(case when (isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate()) then 1 else 0 end) as handle,handle_time," +
                    "DocVersion from t482101H " +
                    "where docCode=" + GridUtils.prossSqlParm(docCode);
            return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(t482101HEntity.class)).get(0);
        } catch (Exception e) {
@@ -205,8 +215,8 @@
    public List<t482101HList> getReceivingMailList(String email, Integer mailType, boolean isNoRead, String userCode) {
        String sql = "set nocount on\n";
        try {
            sql += "select companyId,companyName,mailType,DocCode,sender,receiver,subject,plain_text," +
                    "receive_time,update_time,create_time,sender,userCode,userName,folder_id,delete_Flag, " +
            sql += "select companyId,companyName,mailType,DocCode,senderName,sender,receiver,subject,plain_text," +
                    "receive_time,update_time,create_time,senderName,sender,userCode,userName,folder_id,delete_Flag, " +
                    "read_Flag,(case when (isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate()) then 1 else 0 end) as handle," +
                    "handle_time from t482101H ";
            sql += " where userCode=" + GridUtils.prossSqlParm(userCode);
@@ -240,13 +250,14 @@
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateMailDrafts(t482101HEntity mail) {
        String sql = "set nocount on\n";
        try {
            sql += "update t482101H set sender=" + GridUtils.prossSqlParm(mail.getSender()) + ",receiver=" + GridUtils.prossSqlParm(StringUtils.join(mail.getReceiver(), ",")) + "," +
                    "cc=" + GridUtils.prossSqlParm(StringUtils.join(mail.getCc(), ",")) + ",bcc=" + GridUtils.prossSqlParm(StringUtils.join(mail.getBcc(), ",")) + ",subject=" + GridUtils.prossSqlParm(mail.getSubject()) + "," +
                    "cc=" + GridUtils.prossSqlParm(StringUtils.join(mail.getCc(), ",")) + ",bcc=" + GridUtils.prossSqlParm(StringUtils.join(mail.getBcc(), ",")) + "," +
                    "subject=" + GridUtils.prossSqlParm(mail.getSubject()) + ",messageId=" + GridUtils.prossSqlParm(mail.getMessageId()) + "," +
                    "content=" + GridUtils.prossSqlParm(mail.getContent()) + ",attachment_list=" + GridUtils.prossSqlParm(mail.getAttachmentList()) + ",mailType=" + mail.getMailType() + "," +
                    "update_time=getdate() \n";
            sql += " where docCode=" + GridUtils.prossSqlParm(mail.getDocCode());
@@ -275,30 +286,50 @@
        }
        String[] array = unIdSeq.split(";");
        unId = array[0];//在有值时候第一个必定是unId
        ArrayList<String> seqs = new ArrayList<>(Arrays.asList(array));
        seqs.remove(0);//去掉第一个元素(UNID)
        ArrayList<String> fieldId = new ArrayList<>(Arrays.asList(array));
        fieldId.remove(0);//去掉第一个元素(UNID)
        String sql = " set nocount on \n"
                + " declare @unid varchar(50) = " + GridUtils.prossSqlParm(unId) + "  \n";
                + " declare @unid varchar(50) = " + GridUtils.prossSqlParm(unId) +
                ",@fieldid varchar(1000) = " + GridUtils.prossSqlParm(StringUtils.join(fieldId, ",")) + " \n";
        sql += " select UNID,seq,DocCode,RowId,FieldId,FormId, \n"
                + " PhysicalPath,PhysicalFile,OriginalFileName,FileSize,FileType, \n"
                + " AuthorCode,AuthorName,SmallPicPath,UploadTime,OriginalPicture \n"
                + " from _sys_Attachment \n"
                + " where unid = @unid ";
        if (seqs.size() > 0) {
            sql += " and seq in(" + StringUtils.join(seqs, ",") + ")\n";
        if (fieldId.size() > 0) {
            if (isNumeric(fieldId.get(0))) {
                sql += " and seq in(select list from GetInStr(@fieldid)) \n";
            } else {
                sql += " and fieldid in(select list from GetInStr(@fieldid)) \n";
            }
        }
        List<Map<String, Object>> list = this.jdbcTemplate.queryForList(sql);
        List<AttachmentEntity> attachmentList = new ArrayList<AttachmentEntity>();
        for (int i = 0; list != null && i < list.size(); i++) {
            AttachmentEntity attachment = new AttachmentEntity();
            attachment.setUnid(unId);
            attachment.setPhysicalFile(list.get(i).get("PhysicalFile") == null ? null : (String) list.get(i).get("PhysicalFile"));
            attachment.setOriginalFileName(list.get(i).get("OriginalFileName") == null ? null : (String) list.get(i).get("OriginalFileName"));
            //附件处理
            attachment.setOriginalPicture(list.get(i).get("OriginalPicture") == null ? null : (byte[]) list.get(i).get("OriginalPicture"));
            attachment.setOriginalPicture(list.get(i).get("OriginalPicture") == null ? null : (byte[]) list.get(i).get("OriginalPicture"));  //附件处理
            attachmentList.add(attachment);
        }
        return attachmentList;
    }
    /**
     * 判断是否为数字
     *
     * @param str
     * @return
     */
    private static boolean isNumeric(String str) {
        Pattern pattern = Pattern.compile("\\d+");
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer deleteAttachment(List<String> unId) {
        try {
@@ -331,7 +362,7 @@
            throw e;
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void updateRead(String docCode, boolean status) {
        String sql = " set nocount on \n";
@@ -423,7 +454,7 @@
            throw e;
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void updateMailHandle(String handleTime, String docCode) {
        String sql = " set nocount on \n";
src/com/yc/crm/mail/service/MailQuickTextImpl.java
@@ -6,6 +6,7 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@@ -18,6 +19,7 @@
 */
@Service
public class MailQuickTextImpl extends BaseService implements MailQuickTextIfc {
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveQuickText(T482108Entity quickText) {
        String sql = "set nocount on\n";
@@ -32,7 +34,7 @@
            throw e;
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateQuickText(T482108Entity quickText) {
        String sql = "set nocount on\n";
src/com/yc/crm/mail/service/MailServiceImpl.java
@@ -41,19 +41,29 @@
    @Override
    public void receivingEmails(T482102Entity emailEntity, FoundationEntity foundation) throws MessagingException {
        String imapServer = emailEntity.getReceiveHost();//"imap.qq.com";
        String user = emailEntity.getReceiveEmail();//"xxx@qq.com";
        String pwd = emailEntity.getReceivePassword();//"xxxx";
        String protocol = emailEntity.getReceiveProtocol().toLowerCase();//接收协议 imap pop3
        String server = emailEntity.getReceiveHost();//"imap.qq.com";
        Integer port = emailEntity.getReceivePort();//993
        String user = emailEntity.getReceiveEmail();//邮箱
        String pwd = emailEntity.getReceivePassword();//密码
        Properties properties = new Properties();
        properties.put("mail.store.protocol", "imaps");//emailEntity.getReceiveProtocol()); // IMAP over SSL
        properties.put("mail.imaps.host", emailEntity.getReceiveHost());
        properties.put("mail.imaps.port", emailEntity.getReceivePort());
        properties.put("mail.imaps.starttls.enable", "true");//// IMAP 协议设置 STARTTLS
        properties.put("mail.store.protocol", protocol); // IMAP over SSL
        if (protocol.contains("imap")) {//接收协议imap
            properties.put("mail.imaps.host", server);
            properties.put("mail.imaps.port", port);
        } else if (protocol.contains("pop3")) {//接收协议pop3
            properties.put("mail.pop3.host", server);
            properties.put("mail.pop3.port", port);
        } else {//其他(再加)
            properties.put("mail.imaps.host", server);
            properties.put("mail.imaps.port", port);
        }
//        properties.put("mail.imaps.starttls.enable", "true");//// IMAP 协议设置 STARTTLS
        HashMap IAM = new HashMap();
        //带上IMAP ID信息,由key和value组成,例如name,version,vendor,support-email等。
        IAM.put("name", emailEntity.getReceiveEmail());
        IAM.put("name", user);
        IAM.put("version", emailEntity.getDocVersion() + "");
        IAM.put("vendor", emailEntity.getCompanyName());
        IAM.put("support-email", emailEntity.getEmail());
@@ -65,9 +75,9 @@
            }
        });
        //存储对象
        IMAPStore store = (IMAPStore) session.getStore(emailEntity.getReceiveProtocol());//imap协议或pop3协议类型(推荐你使用IMAP协议来存取服务器上的邮件。)
        IMAPStore store = (IMAPStore) session.getStore(protocol);//imap协议或pop3协议类型(推荐你使用IMAP协议来存取服务器上的邮件。)
        //连接
        store.connect(imapServer, user, pwd);
        store.connect(server, user, pwd);
        store.id(IAM);//163邮箱需要,不然会报:A3 NO SELECT Unsafe Login. Please contact kefu@188.com for help
        Folder folder = null;
        try {
@@ -82,12 +92,6 @@
            //获取收件箱邮件(全部)
            Message[] messages = folder.getMessages();
            //根据时间
//            SimpleDateFormat format=new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");//
//            SearchTerm sinceTerm=new FromStringTerm(emailEntity.getCreateTime());//开始时间
//            SearchTerm beforeTerm=new FromStringTerm(format.format(new Date()));//结束时间
//            Message[] messages = folder.search(new AndTerm(sinceTerm,beforeTerm));
            //邮箱封装保存
            setMailContent(messages, emailEntity, foundation);
@@ -124,16 +128,19 @@
                    t482101H.setMailType(0);//草稿箱状态
                    t482101H = mailIfc.saveReceivingMail(t482101H);//保存到草稿箱内
                }
                throw new Exception("找不到邮箱:" + t482101H.getSender() + "配置信息请完善。邮件已保存到草稿箱#" + t482101H.getDocCode());
                throw new MessagingException("找不到邮箱:" + t482101H.getSender() + "配置信息请完善。邮件已保存到草稿箱#" + t482101H.getDocCode());
            }
            //有发送的邮件保存到后台数据库
            //邮箱服务器配置
            Properties properties = new Properties();
            properties.setProperty("mail.smtp.auth", "true");// // 设置SMTP是否需要认证 指定客户端是否向邮件服务器提交认证
            properties.setProperty("mail.transport.protocol", "smtp");//设置传输协议 指定采用的邮件发送协议。
            properties.put("mail.smtp.ssl.enable", emailEntity.isSmtpSSL() + "");// // 设置启用SSL加密
            properties.setProperty("mail.smtp.host", emailEntity.getSmtpHost());
            properties.setProperty("mail.smtp.port", emailEntity.getSmtpPort() + "");
            properties.setProperty("mail.smtp.auth", "true");// // 设置SMTP是否需要认证
            properties.put("mail.smtp.ssl.enable", emailEntity.isSmtpSSL() + "");// // 设置启用SSL加密
            properties.setProperty("mail.smtp.starttls.enable", "true");//// SMTP 协议设置 STARTTLS  开启tls
//            properties.setProperty("mail.smtp.starttls.enable", "true");//// SMTP 协议设置 STARTTLS  开启tls
//            properties.setProperty("mail.smtp.socketFactory.port", emailEntity.getSmtpPort() + "");
            //
            String sendEmail = emailEntity.getSmtpEmail();//发件人
@@ -197,7 +204,7 @@
            } catch (MessagingException m) {//发送异常处理
                t482101H.setMailType(0);//草稿箱状态
                mailIfc.updateMailDrafts(t482101H);//更新成草稿箱
                throw new Exception("发送邮件异常,邮件已保存在草稿箱。异常原因:" + m.getCause() != null ? m.getCause().getMessage() : m.getMessage());
                throw new MessagingException("发送邮件异常,邮件已保存在草稿箱。异常原因:" + m.getMessage() + "#" + t482101H.getDocCode());
            }
        } catch (Exception e) {
            throw e;
@@ -285,6 +292,7 @@
                    mail.setPlainText(plainText.toString().trim());//明文
                    String from = MimeUtility.decodeText(m.getFrom()[0].toString());
                    InternetAddress internetAddress = new InternetAddress(from);
                    mail.setSenderName(internetAddress.getPersonal());//发件人名称
                    mail.setSender(internetAddress.getAddress());//发件人
                    from = MimeUtility.decodeText(m.getRecipients(Message.RecipientType.TO)[0].toString());
                    internetAddress = new InternetAddress(from);
@@ -317,8 +325,8 @@
                }
            }
            if (t482101HEntityList.size() > 0) {
                mailAccountIfc.updateEmailTime(email.getAccountId());//更新一次配置
                mailIfc.saveReceivingMailList(t482101HEntityList);//保存
                mailAccountIfc.updateEmailTime(email.getAccountId());//更新一次配置
            }
        } catch (Exception e) {
            throw e;
src/com/yc/crm/mail/service/MailSignatureImpl.java
@@ -6,6 +6,7 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@@ -18,6 +19,7 @@
 */
@Service
public class MailSignatureImpl extends BaseService implements MailSignatureIfc {
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveSignature(T482109Entity Signature) {
        String sql = "set nocount on\n";
@@ -32,7 +34,7 @@
            throw e;
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateSignature(T482109Entity Signature) {
        String sql = "set nocount on\n";
@@ -45,7 +47,7 @@
            throw e;
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer deleteSignature(String userCode,Integer sigId) {
        String sql = "set nocount on\n";
src/com/yc/crm/mail/service/MailTagImpl.java
@@ -6,6 +6,7 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@@ -18,6 +19,7 @@
 */
@Service
public class MailTagImpl extends BaseService implements MailTagIfc {
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveTag(T482115Entity tag) {
        String sql = "set nocount on\n";
@@ -32,7 +34,7 @@
            throw e;
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateTag(T482115Entity tag) {
        String sql = "set nocount on\n";
@@ -47,7 +49,7 @@
            throw e;
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer deleteTag(String userCode, Integer tagId) {
        String sql = "set nocount on\n";