From d54772815bc34efc76112b5c22def86d3f45faa8 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期二, 05 三月 2024 22:57:39 +0800 Subject: [PATCH] !491 合并flowable工作流功能 * update 优化 表字段映射于数据库保持一致 * remove 删除无用代码 * remove 删除无用代码 * fix 修复 实体类未实现序列化接口问题 * update 优化 表字段映射于数据库保持一致 * update 优化 统一sql名称 * fix 修复 接口名称编写错误 * merge dev * update 调整sql 添加抄送查询 * update 调整菜单 * update 调整sql脚本 * update 调整任务查询 添加抄送 * add 抄送任务 * remove 删除错误代码 * remove 删除无用代码 * update 调整作废,撤销等校验 * fix 修复 流程作废异常问题 * update 优化 flowable 配置到主yml文件 * update 调整 数据排序规则 * fix 修复 数据库无法自动执行建表sql问题 * update 优化 工作流id生成器保持全局统一 * add 添加附件任务查询 * add 添加审批附件上传 * update 调整bpmn文件修复驳回失败问题 * update 调整会签类型转换异常 * add 添加获取运行中流程信息,流程扩展信息,补充注解,删除无用代码 * update 调整流程转换,流程启动,上传新bpmn文件 * update 调整方法 * update 调整模型修改 * fix 修复 user与dept xml 编写错误 * remove 移除原生ui接口,增加新ui接口 * update 优化 下拉选接口数据权限 * update 优化 删除观测用日志记录 * reset 还原修复命名 * update 修复命名 * add 新增 用户、部门、角色、岗位 下拉选接口与代码实现优化 * update 调整任务办理异步时流程状态错误问题 * add 工作流用户查询 * remove 删除无用注释 添加非空校验 * update 优化获取审批记录 * update 调整事件办理 * update 调整工作流选人接口 * Merge branch 'dev' into future/flowable * update 办理调整执行顺序 * update 调整流程办理优化撤销,驳回,草稿等动作 * fix 修复子流程中设置发起人变量错误问题 * Merge branch 'dev' into future/flowable * update 调整流程执行非空校验,调整任务节点执行 * update 调整注释 * add 添加自定义任务监听策略 * !469 update-完善对模型key校验逻辑 * update-修改常量命名 * update-完善对模型key校验逻辑 * add 添加sql脚本 * Merge branch 'dev' into future/flowable * Merge branch 'dev' into future/flowable * Merge branch 'future/flowable' of https://gitee.com/dromara/RuoYi-Vue-… * add 添加SQLserve脚本 * add 添加流程监听示例 * update 调整获取审批记录 * Merge branch 'future/flowable' of https://gitee.com/dromara/RuoYi-Vue-… * update 调整请假查询 修改流程定义查看xml * update 调整流程实例删除 * update 调整sql * add 添加sql脚本 * update 调整sql * update 调整请假申请,调整菜单sql * update 调整设计器保存发起人变量,修改菜单sql * update 依赖调整 * update 调整flw依赖 * update 升级7.0后移除画图mule类型 * update 调整flw依赖 * update 移动模型设计器翻译方法 * update 调整flw依赖 * fix 修复 误删依赖 * Merge remote-tracking branch 'origin/dev' into future/flowable * remove 移除动态表单 * Merge remote-tracking branch 'origin/dev' into future/flowable * update 优化代码结构 * update 调整请假申请包结构 * Merge branch 'dev' into future/flowable * add 添加文件,调整分类查询 * Merge branch 'dev' into future/flowable * Merge branch 'future/flowable' of https://gitee.com/dromara/RuoYi-Vue-… * add bpmn文件 调整流程办理 * Merge branch 'dev' into future/flowable * Merge branch 'future/flowable' of https://gitee.com/dromara/RuoYi-Vue-… * Merge branch '5.X' into future/flowable * update 调整消息发送 * update 调整名称 * update 调整流程实例查询 * add 添加任务催办,任务改派 * fix 修复 用户注册接口校验用户名不区分租户问题 * update 还原待办任务,添加待办消息发送 * update 优化任务待办,排除非待办任务 * Merge branch '5.X' into future/flowable * update 修改流程启动后重新覆盖流程变量,删除并行流程驳回,撤销后,垃圾数据 * update 升级flowable7.0,添加业务单据删除流程信息 * Merge branch '5.X' into future/flowable * add 添加动态表单提交流程 * Merge branch 'future/flowable' of https://gitee.com/dromara/RuoYi-Vue-… * add 添加动态表单单据 * update 升级flowable到7.0.0.M2,调整工作流提交校验,调整工作流工具类 * add 新增流程定义与表单关联 * update 调整修改流程分类后更新流程分类编码 * update 调整流程定义图片预览 * update 调整人员查询 * update 优化作废,撤销等备注 * Merge branch '5.X' into future/flowable * Merge branch 'future/flowable' of https://gitee.com/dromara/RuoYi-Vue-… * fix 解决设计器选择设置流程发起人设置变量有问题 * add 添加引擎调度监听 * merge 合并5.x分支代码 * remove 移除flow-ui * update 调整日志打印 * add 添加按照业务id删除流程记录 * add 添加请假申请示例,添加流程定义文件部署,添加sql菜单 * update 移除流程表单 formConfig 属性,表单配置信息都放一起便于使用。 * update 调整菜单 * add 添加mysql工作流菜单 * update 调整获取加签人,审判记录 * update 调整流程作废 * add 添加任务完成状态 * add 添加加签,减签人员接口 * update 调整任务驳回后设置审批人 * add 添加驳回申请人 * add 添加查询当前租户所有待办,已办任务 * add 添加会签任务加签减签,添加任务作废理由 * update 调整流程实例,流程定义检索 * update 调整撤销流程申请,当前登录人单据 * add 添加办理人名称翻译 * add 添加流程流程实例,流程定义分类查询 * add 添加模型分类查询 * add 添加流程分类 * add 添加流程表单操作相关接口 * fix 修复修改流程历史流程实例错误问题 * update 调整已办任务排序,添加注释 * update 调整用户,用户组查询 * add 添加获取当前任务参与者,优化任务待办,已办 * add 添加当前登录人单据列表,添加单据状态 * update 补充任务撤销事务 * add 添加撤销流程申请 * update 优化流程实例删除 * fix 修复流程实例查询挂起状态错误 * update 优化流程办理 流程挂起抛出异常 * add 添加业务状态枚举。添加流程启动,审批,终止等状态 * update 优化流程启动 * add 添加流程实例作废,运行中流程实例删除,已完成流程实例删除 * add 添加节点信息 * 调整流程预览 * add 添加审批记录 * 还原代码 * fix 修复模型导出错误 * add 增加委托办理,调整流程启动 * add 添加转办任务 * add 添加任务拾取,任务归还,任务终止,任务委托 * fix 修复任务,流程实例分页模糊查询失效 * add 添加流程实例运行中,已结束分页查询 * add 添加通过流程实例id获取历史流程图,添加flowable配置,调整流程办理 * add 添加流程办理,流程待办,已办分页查询 * 删除无用导入 * 调整流程查询租户id * add 添加流程启动 * 添加模型人员用户,组查询 * add 添加模型部署模型校验 * 修改模型部署导出校验 * fix 修复模型画图保存时key不回显问题 * add 添加流程定义转换为模型 * 优化模型编辑校验,流程定义删除,流程定义激活挂起等 * add 添加流程定义删除,流程定义挂起激活,流程定义版本迁移 * 调整ObjectNode.put警告 * 删除无用依赖,优化模型修改,导出,部署非空校验 * 删除无用导入 * 添加流程定义分页,查看图片,查看xml * 添加模型部署,导出模型 * 修改画图账户登录信息 * 添加模型编辑key重复校验,添加租户查询,删除忽略token注解 * 添加模型新增校验 * 添加工作流模型新增,修改,查询,删除 * 【ADD】集成原生Flowable-ui * 添加workflow模块,添加flowable依赖,yml配置信息 --- ruoyi-common/ruoyi-common-mail/src/main/java/org/dromara/common/mail/utils/Mail.java | 833 +++++++++++++++++++++++++++++----------------------------- 1 files changed, 415 insertions(+), 418 deletions(-) diff --git a/ruoyi-common/ruoyi-common-mail/src/main/java/org/dromara/common/mail/utils/Mail.java b/ruoyi-common/ruoyi-common-mail/src/main/java/org/dromara/common/mail/utils/Mail.java index 4f5a88e..6ca4b69 100644 --- a/ruoyi-common/ruoyi-common-mail/src/main/java/org/dromara/common/mail/utils/Mail.java +++ b/ruoyi-common/ruoyi-common-mail/src/main/java/org/dromara/common/mail/utils/Mail.java @@ -7,7 +7,6 @@ import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; -import cn.hutool.extra.mail.*; import jakarta.activation.DataHandler; import jakarta.activation.DataSource; import jakarta.activation.FileDataSource; @@ -19,10 +18,7 @@ import jakarta.mail.internet.MimeUtility; import jakarta.mail.util.ByteArrayDataSource; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintStream; +import java.io.*; import java.nio.charset.Charset; import java.util.Date; @@ -33,454 +29,455 @@ * @since 3.2.0 */ public class Mail implements Builder<MimeMessage> { - private static final long serialVersionUID = 1L; + @Serial + private static final long serialVersionUID = 1L; - /** - * 閭甯愭埛淇℃伅浠ュ強涓�浜涘鎴风閰嶇疆淇℃伅 - */ - private final MailAccount mailAccount; - /** - * 鏀朵欢浜哄垪琛� - */ - private String[] tos; - /** - * 鎶勯�佷汉鍒楄〃锛坈arbon copy锛� - */ - private String[] ccs; - /** - * 瀵嗛�佷汉鍒楄〃锛坆lind carbon copy锛� - */ - private String[] bccs; - /** - * 鍥炲鍦板潃(reply-to) - */ - private String[] reply; - /** - * 鏍囬 - */ - private String title; - /** - * 鍐呭 - */ - private String content; - /** - * 鏄惁涓篐TML - */ - private boolean isHtml; - /** - * 姝f枃銆侀檮浠跺拰鍥剧墖鐨勬贩鍚堥儴鍒� - */ - private final Multipart multipart = new MimeMultipart(); - /** - * 鏄惁浣跨敤鍏ㄥ眬浼氳瘽锛岄粯璁や负false - */ - private boolean useGlobalSession = false; + /** + * 閭甯愭埛淇℃伅浠ュ強涓�浜涘鎴风閰嶇疆淇℃伅 + */ + private final MailAccount mailAccount; + /** + * 鏀朵欢浜哄垪琛� + */ + private String[] tos; + /** + * 鎶勯�佷汉鍒楄〃锛坈arbon copy锛� + */ + private String[] ccs; + /** + * 瀵嗛�佷汉鍒楄〃锛坆lind carbon copy锛� + */ + private String[] bccs; + /** + * 鍥炲鍦板潃(reply-to) + */ + private String[] reply; + /** + * 鏍囬 + */ + private String title; + /** + * 鍐呭 + */ + private String content; + /** + * 鏄惁涓篐TML + */ + private boolean isHtml; + /** + * 姝f枃銆侀檮浠跺拰鍥剧墖鐨勬贩鍚堥儴鍒� + */ + private final Multipart multipart = new MimeMultipart(); + /** + * 鏄惁浣跨敤鍏ㄥ眬浼氳瘽锛岄粯璁や负false + */ + private boolean useGlobalSession = false; - /** - * debug杈撳嚭浣嶇疆锛屽彲浠ヨ嚜瀹氫箟debug鏃ュ織 - */ - private PrintStream debugOutput; + /** + * debug杈撳嚭浣嶇疆锛屽彲浠ヨ嚜瀹氫箟debug鏃ュ織 + */ + private PrintStream debugOutput; - /** - * 鍒涘缓閭欢瀹㈡埛绔� - * - * @param mailAccount 閭欢甯愬彿 - * @return Mail - */ - public static Mail create(MailAccount mailAccount) { - return new Mail(mailAccount); - } + /** + * 鍒涘缓閭欢瀹㈡埛绔� + * + * @param mailAccount 閭欢甯愬彿 + * @return Mail + */ + public static Mail create(MailAccount mailAccount) { + return new Mail(mailAccount); + } - /** - * 鍒涘缓閭欢瀹㈡埛绔紝浣跨敤鍏ㄥ眬閭欢甯愭埛 - * - * @return Mail - */ - public static Mail create() { - return new Mail(); - } + /** + * 鍒涘缓閭欢瀹㈡埛绔紝浣跨敤鍏ㄥ眬閭欢甯愭埛 + * + * @return Mail + */ + public static Mail create() { + return new Mail(); + } - // --------------------------------------------------------------- Constructor start + // --------------------------------------------------------------- Constructor start - /** - * 鏋勯�狅紝浣跨敤鍏ㄥ眬閭欢甯愭埛 - */ - public Mail() { - this(GlobalMailAccount.INSTANCE.getAccount()); - } + /** + * 鏋勯�狅紝浣跨敤鍏ㄥ眬閭欢甯愭埛 + */ + public Mail() { + this(GlobalMailAccount.INSTANCE.getAccount()); + } - /** - * 鏋勯�� - * - * @param mailAccount 閭欢甯愭埛锛屽鏋滀负null浣跨敤榛樿閰嶇疆鏂囦欢鐨勫叏灞�閭欢閰嶇疆 - */ - public Mail(MailAccount mailAccount) { - mailAccount = (null != mailAccount) ? mailAccount : GlobalMailAccount.INSTANCE.getAccount(); - this.mailAccount = mailAccount.defaultIfEmpty(); - } - // --------------------------------------------------------------- Constructor end + /** + * 鏋勯�� + * + * @param mailAccount 閭欢甯愭埛锛屽鏋滀负null浣跨敤榛樿閰嶇疆鏂囦欢鐨勫叏灞�閭欢閰嶇疆 + */ + public Mail(MailAccount mailAccount) { + mailAccount = (null != mailAccount) ? mailAccount : GlobalMailAccount.INSTANCE.getAccount(); + this.mailAccount = mailAccount.defaultIfEmpty(); + } + // --------------------------------------------------------------- Constructor end - // --------------------------------------------------------------- Getters and Setters start + // --------------------------------------------------------------- Getters and Setters start - /** - * 璁剧疆鏀朵欢浜� - * - * @param tos 鏀朵欢浜哄垪琛� - * @return this - * @see #setTos(String...) - */ - public Mail to(String... tos) { - return setTos(tos); - } + /** + * 璁剧疆鏀朵欢浜� + * + * @param tos 鏀朵欢浜哄垪琛� + * @return this + * @see #setTos(String...) + */ + public Mail to(String... tos) { + return setTos(tos); + } - /** - * 璁剧疆澶氫釜鏀朵欢浜� - * - * @param tos 鏀朵欢浜哄垪琛� - * @return this - */ - public Mail setTos(String... tos) { - this.tos = tos; - return this; - } + /** + * 璁剧疆澶氫釜鏀朵欢浜� + * + * @param tos 鏀朵欢浜哄垪琛� + * @return this + */ + public Mail setTos(String... tos) { + this.tos = tos; + return this; + } - /** - * 璁剧疆澶氫釜鎶勯�佷汉锛坈arbon copy锛� - * - * @param ccs 鎶勯�佷汉鍒楄〃 - * @return this - * @since 4.0.3 - */ - public Mail setCcs(String... ccs) { - this.ccs = ccs; - return this; - } + /** + * 璁剧疆澶氫釜鎶勯�佷汉锛坈arbon copy锛� + * + * @param ccs 鎶勯�佷汉鍒楄〃 + * @return this + * @since 4.0.3 + */ + public Mail setCcs(String... ccs) { + this.ccs = ccs; + return this; + } - /** - * 璁剧疆澶氫釜瀵嗛�佷汉锛坆lind carbon copy锛� - * - * @param bccs 瀵嗛�佷汉鍒楄〃 - * @return this - * @since 4.0.3 - */ - public Mail setBccs(String... bccs) { - this.bccs = bccs; - return this; - } + /** + * 璁剧疆澶氫釜瀵嗛�佷汉锛坆lind carbon copy锛� + * + * @param bccs 瀵嗛�佷汉鍒楄〃 + * @return this + * @since 4.0.3 + */ + public Mail setBccs(String... bccs) { + this.bccs = bccs; + return this; + } - /** - * 璁剧疆澶氫釜鍥炲鍦板潃(reply-to) - * - * @param reply 鍥炲鍦板潃(reply-to)鍒楄〃 - * @return this - * @since 4.6.0 - */ - public Mail setReply(String... reply) { - this.reply = reply; - return this; - } + /** + * 璁剧疆澶氫釜鍥炲鍦板潃(reply-to) + * + * @param reply 鍥炲鍦板潃(reply-to)鍒楄〃 + * @return this + * @since 4.6.0 + */ + public Mail setReply(String... reply) { + this.reply = reply; + return this; + } - /** - * 璁剧疆鏍囬 - * - * @param title 鏍囬 - * @return this - */ - public Mail setTitle(String title) { - this.title = title; - return this; - } + /** + * 璁剧疆鏍囬 + * + * @param title 鏍囬 + * @return this + */ + public Mail setTitle(String title) { + this.title = title; + return this; + } - /** - * 璁剧疆姝f枃<br> - * 姝f枃鍙互鏄櫘閫氭枃鏈篃鍙互鏄疕TML锛堥粯璁ゆ櫘閫氭枃鏈級锛屽彲浠ラ�氳繃璋冪敤{@link #setHtml(boolean)} 璁剧疆鏄惁涓篐TML - * - * @param content 姝f枃 - * @return this - */ - public Mail setContent(String content) { - this.content = content; - return this; - } + /** + * 璁剧疆姝f枃<br> + * 姝f枃鍙互鏄櫘閫氭枃鏈篃鍙互鏄疕TML锛堥粯璁ゆ櫘閫氭枃鏈級锛屽彲浠ラ�氳繃璋冪敤{@link #setHtml(boolean)} 璁剧疆鏄惁涓篐TML + * + * @param content 姝f枃 + * @return this + */ + public Mail setContent(String content) { + this.content = content; + return this; + } - /** - * 璁剧疆鏄惁鏄疕TML - * - * @param isHtml 鏄惁涓篐TML - * @return this - */ - public Mail setHtml(boolean isHtml) { - this.isHtml = isHtml; - return this; - } + /** + * 璁剧疆鏄惁鏄疕TML + * + * @param isHtml 鏄惁涓篐TML + * @return this + */ + public Mail setHtml(boolean isHtml) { + this.isHtml = isHtml; + return this; + } - /** - * 璁剧疆姝f枃 - * - * @param content 姝f枃鍐呭 - * @param isHtml 鏄惁涓篐TML - * @return this - */ - public Mail setContent(String content, boolean isHtml) { - setContent(content); - return setHtml(isHtml); - } + /** + * 璁剧疆姝f枃 + * + * @param content 姝f枃鍐呭 + * @param isHtml 鏄惁涓篐TML + * @return this + */ + public Mail setContent(String content, boolean isHtml) { + setContent(content); + return setHtml(isHtml); + } - /** - * 璁剧疆鏂囦欢绫诲瀷闄勪欢锛屾枃浠跺彲浠ユ槸鍥剧墖鏂囦欢锛屾鏃惰嚜鍔ㄨ缃甤id锛堟鏂囦腑寮曠敤鍥剧墖锛夛紝榛樿cid涓烘枃浠跺悕 - * - * @param files 闄勪欢鏂囦欢鍒楄〃 - * @return this - */ - public Mail setFiles(File... files) { - if (ArrayUtil.isEmpty(files)) { - return this; - } + /** + * 璁剧疆鏂囦欢绫诲瀷闄勪欢锛屾枃浠跺彲浠ユ槸鍥剧墖鏂囦欢锛屾鏃惰嚜鍔ㄨ缃甤id锛堟鏂囦腑寮曠敤鍥剧墖锛夛紝榛樿cid涓烘枃浠跺悕 + * + * @param files 闄勪欢鏂囦欢鍒楄〃 + * @return this + */ + public Mail setFiles(File... files) { + if (ArrayUtil.isEmpty(files)) { + return this; + } - final DataSource[] attachments = new DataSource[files.length]; - for (int i = 0; i < files.length; i++) { - attachments[i] = new FileDataSource(files[i]); - } - return setAttachments(attachments); - } + final DataSource[] attachments = new DataSource[files.length]; + for (int i = 0; i < files.length; i++) { + attachments[i] = new FileDataSource(files[i]); + } + return setAttachments(attachments); + } - /** - * 澧炲姞闄勪欢鎴栧浘鐗囷紝闄勪欢浣跨敤{@link DataSource} 褰㈠紡琛ㄧず锛屽彲浠ヤ娇鐢▄@link FileDataSource}鍖呰鏂囦欢琛ㄧず鏂囦欢闄勪欢 - * - * @param attachments 闄勪欢鍒楄〃 - * @return this - * @since 4.0.9 - */ - public Mail setAttachments(DataSource... attachments) { - if (ArrayUtil.isNotEmpty(attachments)) { - final Charset charset = this.mailAccount.getCharset(); - MimeBodyPart bodyPart; - String nameEncoded; - try { - for (DataSource attachment : attachments) { - bodyPart = new MimeBodyPart(); - bodyPart.setDataHandler(new DataHandler(attachment)); - nameEncoded = attachment.getName(); - if (this.mailAccount.isEncodefilename()) { - nameEncoded = org.dromara.common.mail.utils.InternalMailUtil.encodeText(nameEncoded, charset); - } - // 鏅�氶檮浠舵枃浠跺悕 - bodyPart.setFileName(nameEncoded); - if (StrUtil.startWith(attachment.getContentType(), "image/")) { - // 鍥剧墖闄勪欢锛岀敤浜庢鏂囦腑寮曠敤鍥剧墖 - bodyPart.setContentID(nameEncoded); - } - this.multipart.addBodyPart(bodyPart); - } - } catch (MessagingException e) { - throw new MailException(e); - } - } - return this; - } + /** + * 澧炲姞闄勪欢鎴栧浘鐗囷紝闄勪欢浣跨敤{@link DataSource} 褰㈠紡琛ㄧず锛屽彲浠ヤ娇鐢▄@link FileDataSource}鍖呰鏂囦欢琛ㄧず鏂囦欢闄勪欢 + * + * @param attachments 闄勪欢鍒楄〃 + * @return this + * @since 4.0.9 + */ + public Mail setAttachments(DataSource... attachments) { + if (ArrayUtil.isNotEmpty(attachments)) { + final Charset charset = this.mailAccount.getCharset(); + MimeBodyPart bodyPart; + String nameEncoded; + try { + for (DataSource attachment : attachments) { + bodyPart = new MimeBodyPart(); + bodyPart.setDataHandler(new DataHandler(attachment)); + nameEncoded = attachment.getName(); + if (this.mailAccount.isEncodefilename()) { + nameEncoded = InternalMailUtil.encodeText(nameEncoded, charset); + } + // 鏅�氶檮浠舵枃浠跺悕 + bodyPart.setFileName(nameEncoded); + if (StrUtil.startWith(attachment.getContentType(), "image/")) { + // 鍥剧墖闄勪欢锛岀敤浜庢鏂囦腑寮曠敤鍥剧墖 + bodyPart.setContentID(nameEncoded); + } + this.multipart.addBodyPart(bodyPart); + } + } catch (MessagingException e) { + throw new MailException(e); + } + } + return this; + } - /** - * 澧炲姞鍥剧墖锛屽浘鐗囩殑閿搴斿埌閭欢妯℃澘涓殑鍗犱綅瀛楃涓诧紝鍥剧墖绫诲瀷榛樿涓�"image/jpeg" - * - * @param cid 鍥剧墖涓庡崰浣嶇锛屽崰浣嶇鏍煎紡涓篶id:${cid} - * @param imageStream 鍥剧墖鏂囦欢 - * @return this - * @since 4.6.3 - */ - public Mail addImage(String cid, InputStream imageStream) { - return addImage(cid, imageStream, null); - } + /** + * 澧炲姞鍥剧墖锛屽浘鐗囩殑閿搴斿埌閭欢妯℃澘涓殑鍗犱綅瀛楃涓诧紝鍥剧墖绫诲瀷榛樿涓�"image/jpeg" + * + * @param cid 鍥剧墖涓庡崰浣嶇锛屽崰浣嶇鏍煎紡涓篶id:${cid} + * @param imageStream 鍥剧墖鏂囦欢 + * @return this + * @since 4.6.3 + */ + public Mail addImage(String cid, InputStream imageStream) { + return addImage(cid, imageStream, null); + } - /** - * 澧炲姞鍥剧墖锛屽浘鐗囩殑閿搴斿埌閭欢妯℃澘涓殑鍗犱綅瀛楃涓� - * - * @param cid 鍥剧墖涓庡崰浣嶇锛屽崰浣嶇鏍煎紡涓篶id:${cid} - * @param imageStream 鍥剧墖娴侊紝涓嶅叧闂� - * @param contentType 鍥剧墖绫诲瀷锛宯ull璧嬪�奸粯璁ょ殑"image/jpeg" - * @return this - * @since 4.6.3 - */ - public Mail addImage(String cid, InputStream imageStream, String contentType) { - ByteArrayDataSource imgSource; - try { - imgSource = new ByteArrayDataSource(imageStream, ObjectUtil.defaultIfNull(contentType, "image/jpeg")); - } catch (IOException e) { - throw new IORuntimeException(e); - } - imgSource.setName(cid); - return setAttachments(imgSource); - } + /** + * 澧炲姞鍥剧墖锛屽浘鐗囩殑閿搴斿埌閭欢妯℃澘涓殑鍗犱綅瀛楃涓� + * + * @param cid 鍥剧墖涓庡崰浣嶇锛屽崰浣嶇鏍煎紡涓篶id:${cid} + * @param imageStream 鍥剧墖娴侊紝涓嶅叧闂� + * @param contentType 鍥剧墖绫诲瀷锛宯ull璧嬪�奸粯璁ょ殑"image/jpeg" + * @return this + * @since 4.6.3 + */ + public Mail addImage(String cid, InputStream imageStream, String contentType) { + ByteArrayDataSource imgSource; + try { + imgSource = new ByteArrayDataSource(imageStream, ObjectUtil.defaultIfNull(contentType, "image/jpeg")); + } catch (IOException e) { + throw new IORuntimeException(e); + } + imgSource.setName(cid); + return setAttachments(imgSource); + } - /** - * 澧炲姞鍥剧墖锛屽浘鐗囩殑閿搴斿埌閭欢妯℃澘涓殑鍗犱綅瀛楃涓� - * - * @param cid 鍥剧墖涓庡崰浣嶇锛屽崰浣嶇鏍煎紡涓篶id:${cid} - * @param imageFile 鍥剧墖鏂囦欢 - * @return this - * @since 4.6.3 - */ - public Mail addImage(String cid, File imageFile) { - InputStream in = null; - try { - in = FileUtil.getInputStream(imageFile); - return addImage(cid, in, FileTypeMap.getDefaultFileTypeMap().getContentType(imageFile)); - } finally { - IoUtil.close(in); - } - } + /** + * 澧炲姞鍥剧墖锛屽浘鐗囩殑閿搴斿埌閭欢妯℃澘涓殑鍗犱綅瀛楃涓� + * + * @param cid 鍥剧墖涓庡崰浣嶇锛屽崰浣嶇鏍煎紡涓篶id:${cid} + * @param imageFile 鍥剧墖鏂囦欢 + * @return this + * @since 4.6.3 + */ + public Mail addImage(String cid, File imageFile) { + InputStream in = null; + try { + in = FileUtil.getInputStream(imageFile); + return addImage(cid, in, FileTypeMap.getDefaultFileTypeMap().getContentType(imageFile)); + } finally { + IoUtil.close(in); + } + } - /** - * 璁剧疆瀛楃闆嗙紪鐮� - * - * @param charset 瀛楃闆嗙紪鐮� - * @return this - * @see MailAccount#setCharset(Charset) - */ - public Mail setCharset(Charset charset) { - this.mailAccount.setCharset(charset); - return this; - } + /** + * 璁剧疆瀛楃闆嗙紪鐮� + * + * @param charset 瀛楃闆嗙紪鐮� + * @return this + * @see MailAccount#setCharset(Charset) + */ + public Mail setCharset(Charset charset) { + this.mailAccount.setCharset(charset); + return this; + } - /** - * 璁剧疆鏄惁浣跨敤鍏ㄥ眬浼氳瘽锛岄粯璁や负true - * - * @param isUseGlobalSession 鏄惁浣跨敤鍏ㄥ眬浼氳瘽锛岄粯璁や负true - * @return this - * @since 4.0.2 - */ - public Mail setUseGlobalSession(boolean isUseGlobalSession) { - this.useGlobalSession = isUseGlobalSession; - return this; - } + /** + * 璁剧疆鏄惁浣跨敤鍏ㄥ眬浼氳瘽锛岄粯璁や负true + * + * @param isUseGlobalSession 鏄惁浣跨敤鍏ㄥ眬浼氳瘽锛岄粯璁や负true + * @return this + * @since 4.0.2 + */ + public Mail setUseGlobalSession(boolean isUseGlobalSession) { + this.useGlobalSession = isUseGlobalSession; + return this; + } - /** - * 璁剧疆debug杈撳嚭浣嶇疆锛屽彲浠ヨ嚜瀹氫箟debug鏃ュ織 - * - * @param debugOutput debug杈撳嚭浣嶇疆 - * @return this - * @since 5.5.6 - */ - public Mail setDebugOutput(PrintStream debugOutput) { - this.debugOutput = debugOutput; - return this; - } - // --------------------------------------------------------------- Getters and Setters end + /** + * 璁剧疆debug杈撳嚭浣嶇疆锛屽彲浠ヨ嚜瀹氫箟debug鏃ュ織 + * + * @param debugOutput debug杈撳嚭浣嶇疆 + * @return this + * @since 5.5.6 + */ + public Mail setDebugOutput(PrintStream debugOutput) { + this.debugOutput = debugOutput; + return this; + } + // --------------------------------------------------------------- Getters and Setters end - @Override - public MimeMessage build() { - try { - return buildMsg(); - } catch (MessagingException e) { - throw new MailException(e); - } - } + @Override + public MimeMessage build() { + try { + return buildMsg(); + } catch (MessagingException e) { + throw new MailException(e); + } + } - /** - * 鍙戦�� - * - * @return message-id - * @throws MailException 閭欢鍙戦�佸紓甯� - */ - public String send() throws MailException { - try { - return doSend(); - } catch (MessagingException e) { - if (e instanceof SendFailedException) { - // 褰撳湴鍧�鏃犳晥鏃讹紝鏄剧ず鏇村姞璇︾粏鐨勬棤鏁堝湴鍧�淇℃伅 - final Address[] invalidAddresses = ((SendFailedException) e).getInvalidAddresses(); - final String msg = StrUtil.format("Invalid Addresses: {}", ArrayUtil.toString(invalidAddresses)); - throw new MailException(msg, e); - } - throw new MailException(e); - } - } + /** + * 鍙戦�� + * + * @return message-id + * @throws MailException 閭欢鍙戦�佸紓甯� + */ + public String send() throws MailException { + try { + return doSend(); + } catch (MessagingException e) { + if (e instanceof SendFailedException) { + // 褰撳湴鍧�鏃犳晥鏃讹紝鏄剧ず鏇村姞璇︾粏鐨勬棤鏁堝湴鍧�淇℃伅 + final Address[] invalidAddresses = ((SendFailedException) e).getInvalidAddresses(); + final String msg = StrUtil.format("Invalid Addresses: {}", ArrayUtil.toString(invalidAddresses)); + throw new MailException(msg, e); + } + throw new MailException(e); + } + } - // --------------------------------------------------------------- Private method start + // --------------------------------------------------------------- Private method start - /** - * 鎵ц鍙戦�� - * - * @return message-id - * @throws MessagingException 鍙戦�佸紓甯� - */ - private String doSend() throws MessagingException { - final MimeMessage mimeMessage = buildMsg(); - Transport.send(mimeMessage); - return mimeMessage.getMessageID(); - } + /** + * 鎵ц鍙戦�� + * + * @return message-id + * @throws MessagingException 鍙戦�佸紓甯� + */ + private String doSend() throws MessagingException { + final MimeMessage mimeMessage = buildMsg(); + Transport.send(mimeMessage); + return mimeMessage.getMessageID(); + } - /** - * 鏋勫缓娑堟伅 - * - * @return {@link MimeMessage}娑堟伅 - * @throws MessagingException 娑堟伅寮傚父 - */ - private MimeMessage buildMsg() throws MessagingException { - final Charset charset = this.mailAccount.getCharset(); - final MimeMessage msg = new MimeMessage(getSession()); - // 鍙戜欢浜� - final String from = this.mailAccount.getFrom(); - if (StrUtil.isEmpty(from)) { - // 鐢ㄦ埛鏈彁渚涘彂閫佹柟锛屽垯浠嶴ession涓嚜鍔ㄨ幏鍙� - msg.setFrom(); - } else { - msg.setFrom(org.dromara.common.mail.utils.InternalMailUtil.parseFirstAddress(from, charset)); - } - // 鏍囬 - msg.setSubject(this.title, (null == charset) ? null : charset.name()); - // 鍙戦�佹椂闂� - msg.setSentDate(new Date()); - // 鍐呭鍜岄檮浠� - msg.setContent(buildContent(charset)); - // 鏀朵欢浜� - msg.setRecipients(MimeMessage.RecipientType.TO, org.dromara.common.mail.utils.InternalMailUtil.parseAddressFromStrs(this.tos, charset)); - // 鎶勯�佷汉 - if (ArrayUtil.isNotEmpty(this.ccs)) { - msg.setRecipients(MimeMessage.RecipientType.CC, org.dromara.common.mail.utils.InternalMailUtil.parseAddressFromStrs(this.ccs, charset)); - } - // 瀵嗛�佷汉 - if (ArrayUtil.isNotEmpty(this.bccs)) { - msg.setRecipients(MimeMessage.RecipientType.BCC, org.dromara.common.mail.utils.InternalMailUtil.parseAddressFromStrs(this.bccs, charset)); - } - // 鍥炲鍦板潃(reply-to) - if (ArrayUtil.isNotEmpty(this.reply)) { - msg.setReplyTo(InternalMailUtil.parseAddressFromStrs(this.reply, charset)); - } + /** + * 鏋勫缓娑堟伅 + * + * @return {@link MimeMessage}娑堟伅 + * @throws MessagingException 娑堟伅寮傚父 + */ + private MimeMessage buildMsg() throws MessagingException { + final Charset charset = this.mailAccount.getCharset(); + final MimeMessage msg = new MimeMessage(getSession()); + // 鍙戜欢浜� + final String from = this.mailAccount.getFrom(); + if (StrUtil.isEmpty(from)) { + // 鐢ㄦ埛鏈彁渚涘彂閫佹柟锛屽垯浠嶴ession涓嚜鍔ㄨ幏鍙� + msg.setFrom(); + } else { + msg.setFrom(InternalMailUtil.parseFirstAddress(from, charset)); + } + // 鏍囬 + msg.setSubject(this.title, (null == charset) ? null : charset.name()); + // 鍙戦�佹椂闂� + msg.setSentDate(new Date()); + // 鍐呭鍜岄檮浠� + msg.setContent(buildContent(charset)); + // 鏀朵欢浜� + msg.setRecipients(MimeMessage.RecipientType.TO, InternalMailUtil.parseAddressFromStrs(this.tos, charset)); + // 鎶勯�佷汉 + if (ArrayUtil.isNotEmpty(this.ccs)) { + msg.setRecipients(MimeMessage.RecipientType.CC, InternalMailUtil.parseAddressFromStrs(this.ccs, charset)); + } + // 瀵嗛�佷汉 + if (ArrayUtil.isNotEmpty(this.bccs)) { + msg.setRecipients(MimeMessage.RecipientType.BCC, InternalMailUtil.parseAddressFromStrs(this.bccs, charset)); + } + // 鍥炲鍦板潃(reply-to) + if (ArrayUtil.isNotEmpty(this.reply)) { + msg.setReplyTo(InternalMailUtil.parseAddressFromStrs(this.reply, charset)); + } - return msg; - } + return msg; + } - /** - * 鏋勫缓閭欢淇℃伅涓讳綋 - * - * @param charset 缂栫爜锛寋@code null}鍒欎娇鐢▄@link MimeUtility#getDefaultJavaCharset()} - * @return 閭欢淇℃伅涓讳綋 - * @throws MessagingException 娑堟伅寮傚父 - */ - private Multipart buildContent(Charset charset) throws MessagingException { - final String charsetStr = null != charset ? charset.name() : MimeUtility.getDefaultJavaCharset(); - // 姝f枃 - final MimeBodyPart body = new MimeBodyPart(); - body.setContent(content, StrUtil.format("text/{}; charset={}", isHtml ? "html" : "plain", charsetStr)); - this.multipart.addBodyPart(body); + /** + * 鏋勫缓閭欢淇℃伅涓讳綋 + * + * @param charset 缂栫爜锛寋@code null}鍒欎娇鐢▄@link MimeUtility#getDefaultJavaCharset()} + * @return 閭欢淇℃伅涓讳綋 + * @throws MessagingException 娑堟伅寮傚父 + */ + private Multipart buildContent(Charset charset) throws MessagingException { + final String charsetStr = null != charset ? charset.name() : MimeUtility.getDefaultJavaCharset(); + // 姝f枃 + final MimeBodyPart body = new MimeBodyPart(); + body.setContent(content, StrUtil.format("text/{}; charset={}", isHtml ? "html" : "plain", charsetStr)); + this.multipart.addBodyPart(body); - return this.multipart; - } + return this.multipart; + } - /** - * 鑾峰彇榛樿閭欢浼氳瘽<br> - * 濡傛灉涓哄叏灞�鍗曚緥鐨勪細璇濓紝鍒欏叏灞�鍙厑璁镐竴涓偖浠跺笎鍙凤紝鍚﹀垯姣忔鍙戦�侀偖浠朵細鏂板缓涓�涓柊鐨勪細璇� - * - * @return 閭欢浼氳瘽 {@link Session} - */ - private Session getSession() { - final Session session = MailUtils.getSession(this.mailAccount, this.useGlobalSession); + /** + * 鑾峰彇榛樿閭欢浼氳瘽<br> + * 濡傛灉涓哄叏灞�鍗曚緥鐨勪細璇濓紝鍒欏叏灞�鍙厑璁镐竴涓偖浠跺笎鍙凤紝鍚﹀垯姣忔鍙戦�侀偖浠朵細鏂板缓涓�涓柊鐨勪細璇� + * + * @return 閭欢浼氳瘽 {@link Session} + */ + private Session getSession() { + final Session session = MailUtils.getSession(this.mailAccount, this.useGlobalSession); - if (null != this.debugOutput) { - session.setDebugOut(debugOutput); - } + if (null != this.debugOutput) { + session.setDebugOut(debugOutput); + } - return session; - } - // --------------------------------------------------------------- Private method end + return session; + } + // --------------------------------------------------------------- Private method end } -- Gitblit v1.9.3