mirror of
https://github.com/Hizenberg469/secure_mailer.git
synced 2026-04-19 16:52:24 +03:00
attachment problem resolved
This commit is contained in:
@@ -26,6 +26,7 @@ import java.util.Properties;
|
||||
import javax.mail.Folder;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Store;
|
||||
import javax.mail.Part;
|
||||
|
||||
public class EmailSendingService extends Service<Void> {
|
||||
|
||||
@@ -90,6 +91,7 @@ public class EmailSendingService extends Service<Void> {
|
||||
DataSource source = new FileDataSource(file.getAbsolutePath());
|
||||
mimeBodyPart.setDataHandler(new DataHandler(source));
|
||||
mimeBodyPart.setFileName(file.getName());
|
||||
mimeBodyPart.setDisposition(Part.ATTACHMENT);
|
||||
multipart.addBodyPart(mimeBodyPart);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ import javax.mail.internet.MimeBodyPart;
|
||||
import com.secure_mailer.frontend.EmailMessage;
|
||||
import javafx.concurrent.Service;
|
||||
import javafx.concurrent.Task;
|
||||
import javax.mail.Part;
|
||||
|
||||
|
||||
public class MessageRendererService extends Service<Object>{
|
||||
private EmailMessage emailMessage;
|
||||
@@ -71,7 +73,13 @@ public class MessageRendererService extends Service<Object>{
|
||||
for (int i = multipart.getCount() - 1; i >=0; i--) {
|
||||
BodyPart bodyPart = multipart.getBodyPart(i);
|
||||
String contentType = bodyPart.getContentType();
|
||||
if (isSimpleType(contentType)) {
|
||||
|
||||
// Check if it is an attachment
|
||||
String disposition = bodyPart.getDisposition();
|
||||
if (disposition != null && disposition.equalsIgnoreCase(Part.ATTACHMENT) ) {
|
||||
MimeBodyPart mbp = (MimeBodyPart) bodyPart;
|
||||
if (!emailMessage.isAttachmentLoaded())emailMessage.addAttachment(mbp);
|
||||
} else if (isSimpleType(contentType)) {
|
||||
|
||||
if( emailMessage.getIsAuthenticated() ) {
|
||||
stringBuffer.append(bodyPart.getContent().toString());
|
||||
@@ -83,9 +91,7 @@ public class MessageRendererService extends Service<Object>{
|
||||
} else if (isMultipartType(contentType)){
|
||||
Multipart multipart2 = (Multipart) bodyPart.getContent();
|
||||
loadMultipart(multipart2,stringBuffer);
|
||||
} else if (!isTextPlain(contentType)) {
|
||||
MimeBodyPart mbp = (MimeBodyPart) bodyPart;
|
||||
if (!emailMessage.isAttachmentLoaded())emailMessage.addAttachment(mbp);
|
||||
// } else if (!isTextPlain(contentType)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,8 @@ import javax.mail.BodyPart;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Multipart;
|
||||
import javax.mail.Part;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javafx.fxml.FXMLLoader;
|
||||
@@ -718,20 +720,26 @@ public class MainWindowController extends BaseController implements Initializabl
|
||||
private String loadMultipart(Multipart multipart) throws MessagingException, IOException {
|
||||
|
||||
String msg = "";
|
||||
for (int i = 0; i < multipart.getCount() ; i++) {
|
||||
for (int i = multipart.getCount() - 1; i >= 0 ; i--) {
|
||||
BodyPart bodyPart = multipart.getBodyPart(i);
|
||||
String contentType = bodyPart.getContentType();
|
||||
if (isSimpleType(contentType)) {
|
||||
|
||||
// Check if it is an attachment
|
||||
String disposition = bodyPart.getDisposition();
|
||||
if (disposition != null && disposition.equalsIgnoreCase(Part.ATTACHMENT)) {
|
||||
|
||||
} else if (isSimpleType(contentType)) {
|
||||
|
||||
msg = bodyPart.getContent().toString();
|
||||
|
||||
} else if (isMultipartType(contentType)){
|
||||
Multipart multipart2 = (Multipart) bodyPart.getContent();
|
||||
msg = loadMultipart(multipart2);
|
||||
} else if (!isTextPlain(contentType)) {
|
||||
// MimeBodyPart mbp = (MimeBodyPart) bodyPart;
|
||||
// if (!emailMessage.isAttachmentLoaded())emailMessage.addAttachment(mbp);
|
||||
}
|
||||
}
|
||||
// } else if (!isTextPlain(contentType)) {
|
||||
//// MimeBodyPart mbp = (MimeBodyPart) bodyPart;
|
||||
//// if (!emailMessage.isAttachmentLoaded())emailMessage.addAttachment(mbp);
|
||||
// }
|
||||
}
|
||||
|
||||
return msg;
|
||||
|
||||
Reference in New Issue
Block a user