Update of /var/cvs/applications/email/src/org/mmbase/module/smtp
In directory james.mmbase.org:/tmp/cvs-serv12708
Modified Files:
CloudMailHandler.java SMTPFetcher.java
Log Message:
TO recipients wher enot correctly filled in the Message Objects
See also:
http://cvs.mmbase.org/viewcvs/applications/email/src/org/mmbase/module/smtp
Index: CloudMailHandler.java
===================================================================
RCS file:
/var/cvs/applications/email/src/org/mmbase/module/smtp/CloudMailHandler.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- CloudMailHandler.java 21 Dec 2007 10:16:06 -0000 1.9
+++ CloudMailHandler.java 22 Jan 2008 09:51:39 -0000 1.10
@@ -25,7 +25,7 @@
* This MailHandler dispatched the received Mail Message to MMBase objects.
This makes it possible
* to implement web-mail.
*
- * @version $Id: CloudMailHandler.java,v 1.9 2007/12/21 10:16:06 michiel Exp $
+ * @version $Id: CloudMailHandler.java,v 1.10 2008/01/22 09:51:39 michiel Exp $
*/
public class CloudMailHandler implements MailHandler {
private static final Logger log =
Logging.getLoggerInstance(CloudMailHandler.class);
@@ -43,9 +43,6 @@
MailBox(Node b, Node u) {
box = b; user = u;
}
- public String toString() {
- return user.getNumber() + ":" + box.getNumber();
- }
}
private static class TooBig extends Exception {
@@ -86,13 +83,12 @@
StringBuilder buf = new StringBuilder();
if (values != null) {
log.debug("Using " + values.length + " values");
- for (int i = 0 ; i < values.length; i++) {
- javax.mail.Address value = values[i];
+ for (javax.mail.Address value : values) {
if (buf.length() + value.toString().length() + 2 < maxLength) {
- buf.append(value.toString());
- if (i < values.length) {
+ if (buf.length() > 0) {
buf.append(", ");
}
+ buf.append(value.toString());
} else {
log.warn("Could not store " + value + " for field '" +
fieldName + "' of email node because field can maximully contain " + maxLength
+ " chars");
}
@@ -151,11 +147,10 @@
int deliverCount = 0;
int errorCount = 0;
+ for (MailBox mailbox : mailboxes) {
if (log.isDebugEnabled()) {
- log.debug("Delivering to mailboxes " + mailboxes);
+ log.debug("Delivering to mailbox node " +
mailbox.box.getNumber());
}
- for (MailBox mailbox : mailboxes) {
-
Node email = emailbuilder.createNode();
if (properties.containsKey("emailbuilder.typefield")) {
email.setIntValue(properties.get("emailbuilder.typefield"),
2); // new unread mail
@@ -179,10 +174,13 @@
if (properties.containsKey("emailbuilder.tofield")) {
try {
javax.mail.Address[] value =
message.getRecipients(Message.RecipientType.TO);
+ if (value == null || value.length == 0) {
+ log.warn("No TO-recipients found in " + message);
+ }
nodeSetHeader(email,
properties.get("emailbuilder.tofield"), value);
} catch (MessagingException e) {
errorCount++;
- log.service(e);
+ log.error(e);
}
}
if (properties.containsKey("emailbuilder.ccfield")) {
@@ -542,27 +540,46 @@
return MailBoxStatus.NO_SUCH_USER;
}
Node userNode = nodelist.getNode(0);
- log.debug("User " + userNode.getNumber());
- try {
- Function in = userNode.getFunction("in_mailbox");
- Parameters params = in.createParameters();
+ if (properties.containsKey("mailboxbuilder")) {
+ String where = null;
+ String mailboxbuilder = properties.get("mailboxbuilder");
+ log.debug("Finding mailbox of type " + mailboxbuilder + " for user
" + userNode.getNumber());
+ NodeManager mailboxesManager =
cloud.getNodeManager(mailboxbuilder);
+ NodeQuery query = Queries.createRelatedNodesQuery(userNode,
mailboxesManager, null, null);
+ if (properties.containsKey("mailboxbuilder.where")) {
+ where = properties.get("mailboxbuilder.where");
+ Queries.addConstraints(query, where);
+ }
+ NodeList list = mailboxesManager.getList(query);
+
+ if (list.size() == 1) {
+ Node mailbox = list.getNode(0);
+ mailboxes.add(new MailBox(mailbox, userNode));
+ return MailBoxStatus.OK;
+ } else if (list.size() == 0) {
NoMailBox notfoundaction = NoMailBox.BOUNCE;
if (properties.containsKey("mailboxbuilder.notfound")) {
notfoundaction =
NoMailBox.valueOf(properties.get("mailboxbuilder.notfound").toUpperCase());
}
- params.set("create", notfoundaction == NoMailBox.CREATE);
- Node mailbox =
org.mmbase.util.Casting.toNode(in.getFunctionValue(params), cloud);
- if (mailbox != null) {
- MailBox mb = new MailBox(mailbox, userNode);
- log.debug("found mb " + mb);
- mailboxes.add(mb);
+ switch(notfoundaction) {
+ case CREATE:
+
+ try {
+ log.service("Creting inbox for user " + userNode + "
because one is missing");
+ Node mailbox =
userNode.getFunctionValue("createInbox", null).toNode();
+ mailboxes.add(new MailBox(mailbox, userNode));
return MailBoxStatus.OK;
+ } catch (Exception nfe) {
+ log.error(nfe);
+ return MailBoxStatus.CANT_CREATE_INBOX;
+ }
+ default: return MailBoxStatus.NO_INBOX;
+ }
} else {
- return MailBoxStatus.NO_INBOX;
+ log.error("Too many mailboxes for user '" + user + "'");
+ return MailBoxStatus.TOO_MANY_INBOXES;
}
- } catch (NotFoundException nfe) {
- log.debug(nfe.getMessage() + " coupling to user");
- // no such function
+ } else {
mailboxes.add(new MailBox(userNode, userNode));
return MailBoxStatus.OK;
}
Index: SMTPFetcher.java
===================================================================
RCS file:
/var/cvs/applications/email/src/org/mmbase/module/smtp/SMTPFetcher.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- SMTPFetcher.java 21 Dec 2007 10:16:06 -0000 1.10
+++ SMTPFetcher.java 22 Jan 2008 09:51:39 -0000 1.11
@@ -42,7 +42,7 @@
* TODO: What happens which attached mail-messages? Will those not cause a big
mess?
*
* @author Johannes Verelst <[EMAIL PROTECTED]>
- * @version $Id: SMTPFetcher.java,v 1.10 2007/12/21 10:16:06 michiel Exp $
+ * @version $Id: SMTPFetcher.java,v 1.11 2008/01/22 09:51:39 michiel Exp $
*/
public class SMTPFetcher extends MailFetcher implements Runnable {
private static final Logger log =
Logging.getLoggerInstance(SMTPFetcher.class);
@@ -426,7 +426,7 @@
/**
* Handle the data from the DATA command. This method does all the work:
it creates
- * objects in mailboxes.
+ * a MimeMessage, and dispatches that to the MailHandler(s).
*/
private MailHandler.MessageStatus handleData(String data, Map<String,
String> headers) {
if (log.isTraceEnabled()) {
@@ -447,6 +447,13 @@
log.warn("Exception in MimeMessage instantiation " + t, t);
throw t;
}
+ for (MailHandler.Address recipient : recipients) {
+ try {
+ message.addRecipients(Message.RecipientType.TO,
recipient.toString());
+ } catch (MessagingException e) {
+ log.error(e.getMessage(), e);
+ }
+ }
try {
if (headers != null) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs