feat:修改是否对文件内容解码逻辑
This commit is contained in:
parent
eedcd67113
commit
0c8019ad15
|
@ -566,14 +566,17 @@ public class EmailServiceManager {
|
||||||
final String emlPath = spectrumPathProperties.getEmlPath();
|
final String emlPath = spectrumPathProperties.getEmlPath();
|
||||||
emlFile = new File(rootPath + emlPath + File.separator + fileName);
|
emlFile = new File(rootPath + emlPath + File.separator + fileName);
|
||||||
/* 如果邮件内容经过Base64编码 需要解码后再生成.eml文件 否则直接生成.eml文件 */
|
/* 如果邮件内容经过Base64编码 需要解码后再生成.eml文件 否则直接生成.eml文件 */
|
||||||
List<String> specified = ListUtil.toList("");
|
final String BASE64_FLAG = "Base64";
|
||||||
if (CollUtil.contains(specified, from)){ // 来自指定邮箱 此邮箱对邮件内容进行了Base64编码
|
String content = (String) message.getContent();
|
||||||
|
// 将正文内容分割为两部分: Base64 和 MD5|压缩前大小|压缩后大小|正文Base64编码
|
||||||
|
List<String> contents = StrUtil.split(content, '|', 2);
|
||||||
|
if (StrUtil.equals(contents.get(0), BASE64_FLAG)){
|
||||||
// 先将未解码的内容保存为.eml文件
|
// 先将未解码的内容保存为.eml文件
|
||||||
FileUtil.writeFromStream(message.getInputStream(), emlFile);
|
FileUtil.writeFromStream(message.getInputStream(), emlFile);
|
||||||
// 对正文内容进行解码
|
// content: MD5|压缩前大小|压缩后大小|正文Base64编码
|
||||||
String content = (String) message.getContent();
|
content = contents.get(1);
|
||||||
// String content = FileUtil.readUtf8String(emlFile);
|
// 将content分割为: MD5 和 压缩前大小|压缩后大小|正文Base64编码
|
||||||
List<String> contents = ListUtil.toList(StrUtil.split(content, '|', 2));
|
contents = StrUtil.split(content, '|', 2);
|
||||||
String md5 = contents.get(0);
|
String md5 = contents.get(0);
|
||||||
content = contents.get(1);
|
content = contents.get(1);
|
||||||
if (StrUtil.isBlank(content)) return emlFile;
|
if (StrUtil.isBlank(content)) return emlFile;
|
||||||
|
@ -581,7 +584,7 @@ public class EmailServiceManager {
|
||||||
String md5Verified = MD5.create().digestHex(content);
|
String md5Verified = MD5.create().digestHex(content);
|
||||||
// 如果md5验证失败 则不进行解码
|
// 如果md5验证失败 则不进行解码
|
||||||
if (!StrUtil.equals(md5, md5Verified)) return emlFile;
|
if (!StrUtil.equals(md5, md5Verified)) return emlFile;
|
||||||
contents = ListUtil.toList(StrUtil.split(content, "|"));
|
contents = StrUtil.split(content, '|');
|
||||||
String base64 = contents.get(contents.size() - 1);
|
String base64 = contents.get(contents.size() - 1);
|
||||||
// 解码Base64字符串 并用解码后的内容覆盖未解码内容
|
// 解码Base64字符串 并用解码后的内容覆盖未解码内容
|
||||||
byte[] data = Base64.decode(base64);
|
byte[] data = Base64.decode(base64);
|
||||||
|
@ -589,7 +592,7 @@ public class EmailServiceManager {
|
||||||
InflaterOutputStream inflaterOutputStream = new InflaterOutputStream(out)) {
|
InflaterOutputStream inflaterOutputStream = new InflaterOutputStream(out)) {
|
||||||
inflaterOutputStream.write(data);
|
inflaterOutputStream.write(data);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Create the base64 decoded file[{}] error: {}", emlFile.getAbsolutePath(), e.getMessage());
|
log.error("Create the Base64 decoded file[{}] error: {}", emlFile.getAbsolutePath(), e.getMessage());
|
||||||
}
|
}
|
||||||
} else { // 直接生成.eml文件
|
} else { // 直接生成.eml文件
|
||||||
message.writeTo(Files.newOutputStream(emlFile.toPath()));
|
message.writeTo(Files.newOutputStream(emlFile.toPath()));
|
||||||
|
|
|
@ -50,6 +50,7 @@ public class GardsAlertSystemServiceImpl extends ServiceImpl<GardsAlertSystemMap
|
||||||
// 手动切换为主数据源
|
// 手动切换为主数据源
|
||||||
DynamicDataSourceContextHolder.push("master");
|
DynamicDataSourceContextHolder.push("master");
|
||||||
List<DictModel> items = dictService.getItems(DictConstant.ALERT_SYSTEM_CODE);
|
List<DictModel> items = dictService.getItems(DictConstant.ALERT_SYSTEM_CODE);
|
||||||
|
DynamicDataSourceContextHolder.clear();
|
||||||
Map<String, String> typeMap = items.stream().collect(Collectors
|
Map<String, String> typeMap = items.stream().collect(Collectors
|
||||||
.toMap(DictModel::getValue, DictModel::getText, (oldValue, newValue) -> newValue));
|
.toMap(DictModel::getValue, DictModel::getText, (oldValue, newValue) -> newValue));
|
||||||
page.getRecords().forEach(item -> {
|
page.getRecords().forEach(item -> {
|
||||||
|
@ -62,16 +63,27 @@ public class GardsAlertSystemServiceImpl extends ServiceImpl<GardsAlertSystemMap
|
||||||
@Override
|
@Override
|
||||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||||
public Result<?> saveOrUpdate1(GardsAlertSystem alertSystem) {
|
public Result<?> saveOrUpdate1(GardsAlertSystem alertSystem) {
|
||||||
|
String id = alertSystem.getId();
|
||||||
String code = alertSystem.getCode();
|
String code = alertSystem.getCode();
|
||||||
LambdaQueryWrapper<GardsAlertSystem> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<GardsAlertSystem> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(GardsAlertSystem::getCode, code);
|
wrapper.eq(GardsAlertSystem::getCode, code);
|
||||||
|
if (StrUtil.isBlank(id)){ // 如果是新增,判断code是否已经存在
|
||||||
if (CollUtil.isNotEmpty(this.list(wrapper)))
|
if (CollUtil.isNotEmpty(this.list(wrapper)))
|
||||||
return Result.error("Code " + code + "is exist!");
|
return Result.error("Code " + code + " is exist!");
|
||||||
boolean success = this.saveOrUpdate(alertSystem);
|
if (this.saveOrUpdate(alertSystem))
|
||||||
if (success)
|
return Result.OK(Prompt.ADD_SUCC);
|
||||||
|
return Result.error(Prompt.ADD_ERR);
|
||||||
|
} else { // 如果是修改,判断code是否修改,如果code修改,判断修改的code是否已经存在
|
||||||
|
GardsAlertSystem alertSystemOld = this.getById(id);
|
||||||
|
String oldCode = alertSystemOld.getCode();
|
||||||
|
if (!StrUtil.equals(code, oldCode))
|
||||||
|
if (CollUtil.isNotEmpty(this.list(wrapper)))
|
||||||
|
return Result.error("Code " + code + " is exist!");
|
||||||
|
if (this.saveOrUpdate(alertSystem))
|
||||||
return Result.OK(Prompt.UPDATE_SUCC);
|
return Result.OK(Prompt.UPDATE_SUCC);
|
||||||
return Result.error(Prompt.UPDATE_ERR);
|
return Result.error(Prompt.UPDATE_ERR);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<?> delete(String id) {
|
public Result<?> delete(String id) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user