You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2006/12/15 15:33:19 UTC
svn commit: r487570 - in /incubator/ofbiz/trunk:
applications/content/src/org/ofbiz/content/email/EmailServices.java
framework/common/config/general.properties
Author: jleroux
Date: Fri Dec 15 06:33:18 2006
New Revision: 487570
URL: http://svn.apache.org/viewvc?view=rev&rev=487570
Log:
A new "debug SMTP option" in general.properties to allow easier debugging of SMTP emails.
Modified:
incubator/ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailServices.java
incubator/ofbiz/trunk/framework/common/config/general.properties
Modified: incubator/ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailServices.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailServices.java?view=diff&rev=487570&r1=487569&r2=487570
==============================================================================
--- incubator/ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailServices.java (original)
+++ incubator/ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailServices.java Fri Dec 15 06:33:18 2006
@@ -184,6 +184,8 @@
}
Session session = Session.getInstance(props);
+ boolean debug = UtilProperties.propertyValueEqualsIgnoreCase("general.properties", "mail.debug.on", "Y");
+ session.setDebug(debug);
MimeMessage mail = new MimeMessage(session);
mail.setFrom(new InternetAddress(sendFrom));
@@ -571,27 +573,27 @@
*/
private static Map getParyInfoFromEmailAddress(Address [] addresses, GenericValue userLogin, LocalDispatcher dispatcher) throws GenericServiceException
{
- InternetAddress emailAddress = null;
- Map map = null;
- Map result = null;
+ InternetAddress emailAddress = null;
+ Map map = null;
+ Map result = null;
if (addresses == null) return null;
-
- if (addresses.length > 0) {
- Address addr = addresses[0];
- if (addr instanceof InternetAddress) {
- emailAddress = (InternetAddress)addr;
- }
- }
-
- if (!UtilValidate.isEmpty(emailAddress)) {
- map = new HashMap();
- map.put("address", emailAddress.getAddress());
- map.put("userLogin", userLogin);
- result = dispatcher.runSync("findPartyFromEmailAddress", map);
- }
-
- return result;
+
+ if (addresses.length > 0) {
+ Address addr = addresses[0];
+ if (addr instanceof InternetAddress) {
+ emailAddress = (InternetAddress)addr;
+ }
+ }
+
+ if (!UtilValidate.isEmpty(emailAddress)) {
+ map = new HashMap();
+ map.put("address", emailAddress.getAddress());
+ map.put("userLogin", userLogin);
+ result = dispatcher.runSync("findPartyFromEmailAddress", map);
+ }
+
+ return result;
}
/*
@@ -613,9 +615,9 @@
if (!UtilValidate.isEmpty(emailAddress)) {
result = dispatcher.runSync("findPartyFromEmailAddress",
- UtilMisc.toMap("address", emailAddress.getAddress(), "userLogin", userLogin));
+ UtilMisc.toMap("address", emailAddress.getAddress(), "userLogin", userLogin));
if (result.get("partyId") != null) {
- tempResults.add(result);
+ tempResults.add(result);
}
}
}
@@ -645,45 +647,45 @@
public static String contentIndex = "";
private static Map addMessageBody( Map commEventMap, Multipart multipart)
- throws MessagingException, IOException {
- try {
- int multipartCount = multipart.getCount();
- for (int i=0; i < multipartCount && i < 10; i++) {
- Part part = multipart.getBodyPart(i);
- String thisContentTypeRaw = part.getContentType();
- String content = null;
- int idx2 = thisContentTypeRaw.indexOf(";");
- if (idx2 == -1) idx2 = thisContentTypeRaw.length();
- String thisContentType = thisContentTypeRaw.substring(0, idx2);
- if (thisContentType == null || thisContentType.equals("")) thisContentType = "text/html";
- String disposition = part.getDisposition();
-
- if (thisContentType.startsWith("multipart") || thisContentType.startsWith("Multipart")) {
- contentIndex = contentIndex.concat("." + i);
- return addMessageBody(commEventMap, (Multipart) part.getContent());
- }
- // See this case where the disposition of the inline text is null
- else if ((disposition == null) && (i == 0) && thisContentType.startsWith("text")) {
- content = (String)part.getContent();
- if (UtilValidate.isNotEmpty(content)) {
- contentIndex = contentIndex.concat("." + i);
- commEventMap.put("content", content);
- commEventMap.put("contentMimeTypeId", thisContentType);
- return commEventMap;
- }
- } else if ((disposition != null)
- && (disposition.equals(Part.ATTACHMENT) || disposition.equals(Part.INLINE))
- && thisContentType.startsWith("text")) {
- contentIndex = contentIndex.concat("." + i);
- commEventMap.put("content", part.getContent());
- commEventMap.put("contentMimeTypeId", thisContentType);
- return commEventMap;
- }
- }
- return commEventMap;
- } catch (MessagingException e) {
- Debug.logError(e, module);
- return ServiceUtil.returnError(e.getMessage());
+ throws MessagingException, IOException {
+ try {
+ int multipartCount = multipart.getCount();
+ for (int i=0; i < multipartCount && i < 10; i++) {
+ Part part = multipart.getBodyPart(i);
+ String thisContentTypeRaw = part.getContentType();
+ String content = null;
+ int idx2 = thisContentTypeRaw.indexOf(";");
+ if (idx2 == -1) idx2 = thisContentTypeRaw.length();
+ String thisContentType = thisContentTypeRaw.substring(0, idx2);
+ if (thisContentType == null || thisContentType.equals("")) thisContentType = "text/html";
+ String disposition = part.getDisposition();
+
+ if (thisContentType.startsWith("multipart") || thisContentType.startsWith("Multipart")) {
+ contentIndex = contentIndex.concat("." + i);
+ return addMessageBody(commEventMap, (Multipart) part.getContent());
+ }
+ // See this case where the disposition of the inline text is null
+ else if ((disposition == null) && (i == 0) && thisContentType.startsWith("text")) {
+ content = (String)part.getContent();
+ if (UtilValidate.isNotEmpty(content)) {
+ contentIndex = contentIndex.concat("." + i);
+ commEventMap.put("content", content);
+ commEventMap.put("contentMimeTypeId", thisContentType);
+ return commEventMap;
+ }
+ } else if ((disposition != null)
+ && (disposition.equals(Part.ATTACHMENT) || disposition.equals(Part.INLINE))
+ && thisContentType.startsWith("text")) {
+ contentIndex = contentIndex.concat("." + i);
+ commEventMap.put("content", part.getContent());
+ commEventMap.put("contentMimeTypeId", thisContentType);
+ return commEventMap;
+ }
+ }
+ return commEventMap;
+ } catch (MessagingException e) {
+ Debug.logError(e, module);
+ return ServiceUtil.returnError(e.getMessage());
} catch (IOException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
@@ -720,7 +722,7 @@
* @return
*/
public static Map storeIncomingEmail(DispatchContext dctx, Map context) {
-
+
GenericDelegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
MimeMessageWrapper wrapper = (MimeMessageWrapper) context.get("messageWrapper");
@@ -730,7 +732,7 @@
String partyIdTo = null;
String partyIdFrom = null;
String contentType = null;
- String communicationEventId = null;
+ String communicationEventId = null;
String contactMechIdFrom = null;
String contactMechIdTo = null;
@@ -746,8 +748,8 @@
Address [] addressesCC = message.getRecipients(MimeMessage.RecipientType.CC);
Address [] addressesBCC = message.getRecipients(MimeMessage.RecipientType.BCC);
Debug.logInfo("Processing Incoming Email message from: " +
- (addressesFrom[0] == null? "not found" : addressesFrom[0].toString()) + " to: " +
- (addressesTo[0] == null? "not found" : addressesTo[0].toString()), module);
+ (addressesFrom[0] == null? "not found" : addressesFrom[0].toString()) + " to: " +
+ (addressesTo[0] == null? "not found" : addressesTo[0].toString()), module);
// ignore the message when the spam status = yes
String spamHeaderName = UtilProperties.getPropertyValue("general.properties", "mail.spam.name", "N");
@@ -794,11 +796,11 @@
partyIdTo = (String)result.get("partyId");
contactMechIdTo = (String)result.get("contactMechId");
}
- if (userLogin.get("partyId") == null && partyIdTo != null) {
- int ch = 0;
- for (ch=partyIdTo.length(); ch > 0 && Character.isDigit(partyIdTo.charAt(ch-1)); ch--);
- userLogin.put("partyId", partyIdTo.substring(0,ch)); //allow services to be called to have prefix
- }
+ if (userLogin.get("partyId") == null && partyIdTo != null) {
+ int ch = 0;
+ for (ch=partyIdTo.length(); ch > 0 && Character.isDigit(partyIdTo.charAt(ch-1)); ch--);
+ userLogin.put("partyId", partyIdTo.substring(0,ch)); //allow services to be called to have prefix
+ }
// get the 'from' partyId
result = getParyInfoFromEmailAddress(addressesFrom, userLogin, dispatcher);
@@ -806,31 +808,31 @@
contactMechIdFrom = (String)result.get("contactMechId");
Map commEventMap = new HashMap();
- commEventMap.put("communicationEventTypeId", "AUTO_EMAIL_COMM");
- commEventMap.put("contactMechTypeId", "EMAIL_ADDRESS");
- String subject = message.getSubject();
- commEventMap.put("subject", subject);
-
- commEventMap.put("entryDate", nowTimestamp);
-
- //Set sent and received dates
- commEventMap.put("datetimeStarted", UtilDateTime.toTimestamp(message.getSentDate()));
- commEventMap.put("datetimeEnded", UtilDateTime.toTimestamp(message.getReceivedDate()));
+ commEventMap.put("communicationEventTypeId", "AUTO_EMAIL_COMM");
+ commEventMap.put("contactMechTypeId", "EMAIL_ADDRESS");
+ String subject = message.getSubject();
+ commEventMap.put("subject", subject);
+
+ commEventMap.put("entryDate", nowTimestamp);
+
+ //Set sent and received dates
+ commEventMap.put("datetimeStarted", UtilDateTime.toTimestamp(message.getSentDate()));
+ commEventMap.put("datetimeEnded", UtilDateTime.toTimestamp(message.getReceivedDate()));
// get the content(type) part
- if (contentType.startsWith("text")) {
- commEventMap.put("content", message.getContent());
- commEventMap.put("contentMimeTypeId", contentType);
- } else if (contentType.startsWith("multipart") || contentType.startsWith("Multipart")) {
- contentIndex = "";
- commEventMap = addMessageBody(commEventMap, (Multipart) message.getContent());
- }
-
+ if (contentType.startsWith("text")) {
+ commEventMap.put("content", message.getContent());
+ commEventMap.put("contentMimeTypeId", contentType);
+ } else if (contentType.startsWith("multipart") || contentType.startsWith("Multipart")) {
+ contentIndex = "";
+ commEventMap = addMessageBody(commEventMap, (Multipart) message.getContent());
+ }
+
// store from/to parties, but when not found make a note of the email to/from address in the workEffort Note Section.
String commNote = "";
if (partyIdFrom != null) {
- commEventMap.put("partyIdFrom", partyIdFrom);
- commEventMap.put("contactMechIdFrom", contactMechIdFrom);
+ commEventMap.put("partyIdFrom", partyIdFrom);
+ commEventMap.put("contactMechIdFrom", contactMechIdFrom);
} else {
commNote += "Sent from: " + ((InternetAddress)addressesFrom[0]).getAddress() + "; ";
commNote += "Sent Name from: " + ((InternetAddress)addressesFrom[0]).getPersonal() + "; ";
@@ -859,15 +861,15 @@
commEventMap.put("note", commNote);
}
- commEventMap.put("userLogin", userLogin);
- result = dispatcher.runSync("createCommunicationEvent", commEventMap);
- communicationEventId = (String)result.get("communicationEventId");
+ commEventMap.put("userLogin", userLogin);
+ result = dispatcher.runSync("createCommunicationEvent", commEventMap);
+ communicationEventId = (String)result.get("communicationEventId");
// store attachements
- if (contentType.startsWith("multipart") || contentType.startsWith("Multipart")) {
- int attachmentCount = EmailWorker.addAttachmentsToCommEvent(message, communicationEventId, dispatcher, userLogin);
- if (Debug.infoOn()) Debug.logInfo(attachmentCount + " attachments added to CommunicationEvent:" + communicationEventId,module);
- }
+ if (contentType.startsWith("multipart") || contentType.startsWith("Multipart")) {
+ int attachmentCount = EmailWorker.addAttachmentsToCommEvent(message, communicationEventId, dispatcher, userLogin);
+ if (Debug.infoOn()) Debug.logInfo(attachmentCount + " attachments added to CommunicationEvent:" + communicationEventId,module);
+ }
//For all other addresses create a CommunicationEventRole
while (itr.hasNext()) {
@@ -883,11 +885,11 @@
Map input = UtilMisc.toMap("communicationEventId", communicationEventId, "partyId", partyId, "roleTypeId", "_NA_", "userLogin", userLogin, "contactMechId", (String)address.get("contactMechId"));
dispatcher.runSync("createCommunicationEventRole", input);
}
-
- Map results = ServiceUtil.returnSuccess();
+
+ Map results = ServiceUtil.returnSuccess();
results.put("communicationEventId", communicationEventId);
results.put("statusId", commEventMap.get("statusId"));
- return results;
+ return results;
} catch (MessagingException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
Modified: incubator/ofbiz/trunk/framework/common/config/general.properties
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/common/config/general.properties?view=diff&rev=487570&r1=487569&r2=487570
==============================================================================
--- incubator/ofbiz/trunk/framework/common/config/general.properties (original)
+++ incubator/ofbiz/trunk/framework/common/config/general.properties Fri Dec 15 06:33:18 2006
@@ -48,6 +48,9 @@
#mail.smtp.auth.user=
#mail.smtp.auth.password=
+# -- debug SMTP mail option enabled (Y|N)
+mail.debug.on=N
+
# -- HTTP upload max size in bytes (-1 for unlimited)
http.upload.max.size=-1