|
From: <kc...@us...> - 2003-07-17 08:08:17
|
Update of /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/transport
In directory sc8-pr-cvs1:/tmp/cvs-serv19796/src/hk/hku/cecid/phoenix/message/transport
Modified Files:
Tag: b0931
Mail.java
Log Message:
modified s/mime encryption/decryption calling mechanism to suit ebmail usage
Index: Mail.java
===================================================================
RCS file: /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/transport/Mail.java,v
retrieving revision 1.35.2.4
retrieving revision 1.35.2.5
diff -C2 -d -r1.35.2.4 -r1.35.2.5
*** Mail.java 20 May 2003 04:58:47 -0000 1.35.2.4
--- Mail.java 17 Jul 2003 08:08:13 -0000 1.35.2.5
***************
*** 76,80 ****
import hk.hku.cecid.phoenix.message.packaging.*;
import hk.hku.cecid.phoenix.pki.SMIMEDecrypter;
! import hk.hku.cecid.phoenix.pki.SMIMEEncrypter;
import hk.hku.cecid.phoenix.pki.SMIMEException;
import java.io.BufferedReader;
--- 76,80 ----
import hk.hku.cecid.phoenix.message.packaging.*;
import hk.hku.cecid.phoenix.pki.SMIMEDecrypter;
! //import hk.hku.cecid.phoenix.pki.SMIMEEncrypter;
import hk.hku.cecid.phoenix.pki.SMIMEException;
import java.io.BufferedReader;
***************
*** 88,92 ****
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
! import java.security.cert.CertificateEncodingException;
import java.util.ArrayList;
import java.util.Properties;
--- 88,92 ----
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
! //import java.security.cert.CertificateEncodingException;
import java.util.ArrayList;
import java.util.Properties;
***************
*** 264,268 ****
* Default transfer encoding for MIME messages.
*/
! private static final String MAIL_TRANSFER_ENCODING = "base64";
/**
--- 264,268 ----
* Default transfer encoding for MIME messages.
*/
! public static final String MAIL_TRANSFER_ENCODING = "base64";
/**
***************
*** 521,551 ****
session.setDebug(debug);
! final SOAPMessage soapMessage = ebxmlMessage.getSOAPMessage();
! final boolean hasAttachments =
! soapMessage.getAttachments().hasNext();
! if (hasAttachments) {
! Utility.addContentTransferEncoding(
! soapMessage, MAIL_TRANSFER_ENCODING,
! MAIL_TRANSFER_ENCODING);
! soapMessage.saveChanges();
! }
!
! final ByteArrayOutputStream out = new ByteArrayOutputStream();
! ebxmlMessage.writeTo(out);
! final String[] contentType = soapMessage.getMimeHeaders().
! getHeader(CONTENT_TYPE);
! String type = contentType[0];
! final AttachmentDataSource content =
! new AttachmentDataSource(out.toByteArray(), type);
! MimeMessage mimeMessage = new MimeMessage(session);
! MimeMultipart multipart = null;
! if (hasAttachments) {
! multipart = new MimeMultipart(content);
}
else {
! mimeMessage.setDataHandler(new DataHandler(content));
! mimeMessage.setHeader(Constants.CONTENT_TRANSFER_ENCODING,
! MAIL_TRANSFER_ENCODING);
}
String fromPartyId = ((MessageHeader.PartyId) ebxmlMessage.
getFromPartyIds().next()).getId();
--- 521,567 ----
session.setDebug(debug);
! SOAPMessage soapMessage = null;
! boolean hasAttachments = false;
! MimeMessage mimeMessage = null;
!
! if (ebxmlMessage.isSMIMEEncrypted()) {
! final ByteArrayOutputStream out = new ByteArrayOutputStream();
! ebxmlMessage.writeTo(out);
! mimeMessage = new MimeMessage(
! session, new ByteArrayInputStream(out.toByteArray()));
}
else {
! soapMessage = ebxmlMessage.getSOAPMessage();
! hasAttachments = soapMessage.getAttachments().hasNext();
! if (hasAttachments) {
! Utility.addContentTransferEncoding(
! soapMessage, MAIL_TRANSFER_ENCODING,
! MAIL_TRANSFER_ENCODING);
! soapMessage.saveChanges();
! }
!
! final ByteArrayOutputStream out = new ByteArrayOutputStream();
! ebxmlMessage.writeTo(out);
! final String[] contentType = soapMessage.getMimeHeaders().
! getHeader(CONTENT_TYPE);
! String type = contentType[0];
! final AttachmentDataSource content =
! new AttachmentDataSource(out.toByteArray(), type);
! mimeMessage = new MimeMessage(session);
! MimeMultipart multipart = null;
! if (hasAttachments) {
! multipart = new MimeMultipart(content);
! }
! else {
! mimeMessage.setDataHandler(new DataHandler(content));
! mimeMessage.setHeader(Constants.CONTENT_TRANSFER_ENCODING,
! MAIL_TRANSFER_ENCODING);
! }
!
! if (multipart != null) {
! mimeMessage.setContent(multipart);
! }
}
+
String fromPartyId = ((MessageHeader.PartyId) ebxmlMessage.
getFromPartyIds().next()).getId();
***************
*** 554,573 ****
(MAIL_PREFIX.length(), fromPartyId.length());
}
!
mimeMessage.setFrom(new InternetAddress(fromPartyId));
mimeMessage.setRecipient(Message.RecipientType.TO,
new InternetAddress(toMshUrl));
mimeMessage.setSubject(ebxmlMessage.getConversationId());
- /* some mail servers cannot receive messages correctly
- if the sent date is set */
- // mimeMessage.setSentDate(new Date());
-
mimeMessage.setHeader(SOAP_ACTION, EBXML_SOAP_ACTION);
- if (multipart != null) {
- mimeMessage.setContent(multipart);
- }
mimeMessage.saveChanges();
if (smime) {
mimeMessage = SMIMEEncrypter.getInstance
--- 570,583 ----
(MAIL_PREFIX.length(), fromPartyId.length());
}
!
mimeMessage.setFrom(new InternetAddress(fromPartyId));
mimeMessage.setRecipient(Message.RecipientType.TO,
new InternetAddress(toMshUrl));
mimeMessage.setSubject(ebxmlMessage.getConversationId());
mimeMessage.setHeader(SOAP_ACTION, EBXML_SOAP_ACTION);
mimeMessage.saveChanges();
+ /*
if (smime) {
mimeMessage = SMIMEEncrypter.getInstance
***************
*** 576,579 ****
--- 586,590 ----
createEncryptedMimeMessage(toMshUrl, mimeMessage, session);
}
+ */
try {
***************
*** 587,593 ****
}
! if (hasAttachments) {
! Utility.removeContentTransferEncoding(soapMessage);
! soapMessage.saveChanges();
}
--- 598,607 ----
}
!
! if (!ebxmlMessage.isSMIMEEncrypted()) {
! if (hasAttachments) {
! Utility.removeContentTransferEncoding(soapMessage);
! soapMessage.saveChanges();
! }
}
***************
*** 612,615 ****
--- 626,630 ----
ErrorMessages.ERR_SMTP_CANNOT_COMPOSE_MESSAGE));
}
+ /*
catch (SMIMEException e) {
logger.error(ErrorMessages.getMessage(
***************
*** 630,633 ****
--- 645,649 ----
ErrorMessages.ERR_PKI_INVALID_KEYSTORE));
}
+ */
catch (Exception e) {
String err = ErrorMessages.getMessage(
***************
*** 638,659 ****
}
- /** Receive mails from a remote mail box in <code>smtpHost</code> using
- the specified <code>protocol</code>, <code>username</code> and
- <code>password</code>
-
- @param protocol protocols such as <code>imap</code> or
- <code>pop3</code> to connect to remote mail box
- @param smtpHost SMTP mail server name
- @param port SMTP mail server port
- @param folderName remote mail box name such as <code>INBOX</code>
- @param username username for mail box authentication
- @param password password for mail box authentication
- @return an array of <code>EbxmlMessage</code>s'
- */
public static EbxmlMessage[] receive(String protocol, String smtpHost,
String port, String folderName,
! String username, String password)
throws TransportException {
-
logger.debug("=> Mail.receive");
logger.info("Receiving " + protocol + " messages from " + smtpHost
--- 654,664 ----
}
public static EbxmlMessage[] receive(String protocol, String smtpHost,
String port, String folderName,
! String username, String password,
! String smimeKeyStoreAlias,
! String smimeKeyStorePassword,
! String smimeKeyStoreLocation)
throws TransportException {
logger.debug("=> Mail.receive");
logger.info("Receiving " + protocol + " messages from " + smtpHost
***************
*** 724,737 ****
if (type.toLowerCase().startsWith(SMIME_ENCRYPTED)) {
logger.debug("Message S/MIME encrypted, now decrypt");
! messages[i] = SMIMEDecrypter.getInstance
! (smimeDecKeyStorePath + File.separator
! + smimeDecKeyStoreFile, smimeDecKeyStorePassword).
! decryptMimeMessage(smimeDecKeyStoreAlias,
! smimeDecKeyStorePassword,
! (MimeMessage) messages[i], session);
! mimeHeaders.addHeader(CONTENT_TYPE, messages[i].
! getContentType());
! soapMessage = messageFactory.createMessage
! (mimeHeaders, messages[i].getInputStream());
}
else if (changeSubType && index >= 0) {
--- 729,748 ----
if (type.toLowerCase().startsWith(SMIME_ENCRYPTED)) {
logger.debug("Message S/MIME encrypted, now decrypt");
! if (smimeKeyStoreLocation == null ||
! smimeKeyStoreAlias == null) {
! logger.debug("Cannot decrypt, invalid keystore");
! throw new SMIMEException("Cannot decrypt, invalid keystore");
! }
! else {
! MimeMessage msg = SMIMEDecrypter.getInstance
! (smimeKeyStoreLocation, smimeKeyStorePassword).
! decryptMimeMessage(smimeKeyStoreAlias,
! smimeKeyStorePassword,
! (MimeMessage) messages[i], session);
! mimeHeaders.addHeader(CONTENT_TYPE, msg.
! getContentType());
! soapMessage = messageFactory.createMessage
! (mimeHeaders, msg.getInputStream());
! }
}
else if (changeSubType && index >= 0) {
***************
*** 842,845 ****
--- 853,883 ----
throw new TransportException(err);
}
+ }
+
+ /** Receive mails from a remote mail box in <code>smtpHost</code> using
+ the specified <code>protocol</code>, <code>username</code> and
+ <code>password</code>
+
+ @param protocol protocols such as <code>imap</code> or
+ <code>pop3</code> to connect to remote mail box
+ @param smtpHost SMTP mail server name
+ @param port SMTP mail server port
+ @param folderName remote mail box name such as <code>INBOX</code>
+ @param username username for mail box authentication
+ @param password password for mail box authentication
+ @return an array of <code>EbxmlMessage</code>s'
+ */
+ public static EbxmlMessage[] receive(String protocol, String smtpHost,
+ String port, String folderName,
+ String username, String password)
+ throws TransportException {
+ String smimeKeyStoreLocation = null;
+ if (smimeDecKeyStorePath != null && smimeDecKeyStoreFile != null) {
+ smimeKeyStoreLocation = smimeDecKeyStorePath + File.separator
+ + smimeDecKeyStoreFile;
+ }
+ return receive(protocol, smtpHost, port, folderName, username, password,
+ smimeDecKeyStoreAlias, smimeDecKeyStorePassword,
+ smimeKeyStoreLocation);
}
|