自动处理模块下载邮件代码修改
This commit is contained in:
parent
6c5a0bf546
commit
2407b65a06
|
@ -532,7 +532,8 @@ public class EmailServiceManager {
|
||||||
File emlFile = null;
|
File emlFile = null;
|
||||||
String status = EmailLogManager.STATUS_SUCCESS;
|
String status = EmailLogManager.STATUS_SUCCESS;
|
||||||
Date receivedDate = null;
|
Date receivedDate = null;
|
||||||
FileOutputStream outputStream = null;
|
InputStream inputStream = null;
|
||||||
|
BufferedOutputStream outputStream = null;
|
||||||
try {
|
try {
|
||||||
//获取发件人
|
//获取发件人
|
||||||
final String address = ((InternetAddress) message.getFrom()[0]).getAddress();
|
final String address = ((InternetAddress) message.getFrom()[0]).getAddress();
|
||||||
|
@ -566,25 +567,19 @@ public class EmailServiceManager {
|
||||||
final String rootPath = spectrumPathProperties.getRootPath();
|
final String rootPath = spectrumPathProperties.getRootPath();
|
||||||
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);
|
||||||
outputStream = new FileOutputStream(emlFile);
|
// outputStream = new FileOutputStream(emlFile);
|
||||||
message.writeTo(outputStream);
|
// message.writeTo(outputStream);
|
||||||
|
|
||||||
|
int bufferSize = 1024 * 1024; // 1M
|
||||||
|
inputStream = message.getInputStream();
|
||||||
|
outputStream = new BufferedOutputStream(new FileOutputStream(emlFile), bufferSize);
|
||||||
|
// 从邮件的输入流读取内容,并写入到本地文件
|
||||||
|
byte[] buffer = new byte[bufferSize];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||||
|
outputStream.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
|
||||||
// int bufferSize = 1024 * 1024; // 1M
|
|
||||||
// InputStream inputStream = message.getInputStream();
|
|
||||||
// BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, bufferSize);
|
|
||||||
// // 或者使用 BufferedOutputStream
|
|
||||||
// OutputStream outputStream = new FileOutputStream(emlFile);
|
|
||||||
// BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream, bufferSize);
|
|
||||||
// // 从邮件的输入流读取内容,并写入到本地文件
|
|
||||||
// byte[] buffer = new byte[bufferSize];
|
|
||||||
// int bytesRead;
|
|
||||||
// while ((bytesRead = bufferedInputStream.read(buffer)) != -1) {
|
|
||||||
// bufferedOutputStream.write(buffer, 0, bytesRead);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // 关闭流
|
|
||||||
// bufferedInputStream.close();
|
|
||||||
// bufferedOutputStream.close();
|
|
||||||
} catch (MessagingException | IOException e) {
|
} catch (MessagingException | IOException e) {
|
||||||
// 下载邮件失败 抛出自定义邮件下载异常
|
// 下载邮件失败 抛出自定义邮件下载异常
|
||||||
status = EmailLogManager.STATUS_ERROR;
|
status = EmailLogManager.STATUS_ERROR;
|
||||||
|
@ -598,7 +593,11 @@ public class EmailServiceManager {
|
||||||
(Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath()));
|
(Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath()));
|
||||||
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event);
|
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event);
|
||||||
try {
|
try {
|
||||||
|
if (Objects.nonNull(inputStream)) {
|
||||||
|
inputStream.close();
|
||||||
|
}
|
||||||
if (Objects.nonNull(outputStream)) {
|
if (Objects.nonNull(outputStream)) {
|
||||||
|
outputStream.flush();
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user