Fix bug 262

http://helma.org/bugs/show_bug.cgi?id=262
This commit is contained in:
hns 2003-07-29 14:03:26 +00:00
parent f0d4c51ef6
commit a85de95c0b

View file

@ -177,7 +177,8 @@ public class MailObject extends ScriptableObject implements Serializable {
* @throws Exception ... * @throws Exception ...
* @throws IOException ... * @throws IOException ...
*/ */
public void addPart(Object obj, Object filename) throws Exception { public void addPart(Object obj, Object filename) {
try {
if (obj == null || obj == Undefined.instance) { if (obj == null || obj == Undefined.instance) {
throw new IOException("mail.addPart called with wrong number of arguments."); throw new IOException("mail.addPart called with wrong number of arguments.");
} }
@ -210,6 +211,11 @@ public class MailObject extends ScriptableObject implements Serializable {
} }
multipart.addBodyPart(part); multipart.addBodyPart(part);
} catch (Exception mx) {
System.err.println("Error in MailObject.addPart(): "+mx);
setStatus(MIMEPART);
}
} }
/** /**
@ -219,12 +225,17 @@ public class MailObject extends ScriptableObject implements Serializable {
* *
* @throws Exception ... * @throws Exception ...
*/ */
public void setSubject(Object subject) throws Exception { public void setSubject(Object subject) {
if (subject == null || subject == Undefined.instance) { if (subject == null || subject == Undefined.instance) {
return; return;
} }
try {
message.setSubject(MimeUtility.encodeWord(subject.toString())); message.setSubject(MimeUtility.encodeWord(subject.toString()));
} catch (Exception mx) {
System.err.println("Error in MailObject.setSubject(): "+mx);
setStatus(SUBJECT);
}
} }
/** /**
@ -235,7 +246,8 @@ public class MailObject extends ScriptableObject implements Serializable {
* @throws Exception ... * @throws Exception ...
* @throws AddressException ... * @throws AddressException ...
*/ */
public void setReplyTo(String addstr) throws Exception { public void setReplyTo(String addstr) {
try {
if (addstr.indexOf("@") < 0) { if (addstr.indexOf("@") < 0) {
throw new AddressException(); throw new AddressException();
} }
@ -244,6 +256,10 @@ public class MailObject extends ScriptableObject implements Serializable {
replyTo[0] = new InternetAddress(addstr); replyTo[0] = new InternetAddress(addstr);
message.setReplyTo(replyTo); message.setReplyTo(replyTo);
} catch (Exception mx) {
System.err.println("Error in MailObject.setReplyTo(): "+mx);
setStatus(REPLYTO);
}
} }
/** /**
@ -255,7 +271,8 @@ public class MailObject extends ScriptableObject implements Serializable {
* @throws Exception ... * @throws Exception ...
* @throws AddressException ... * @throws AddressException ...
*/ */
public void setFrom(String addstr, Object name) throws Exception { public void setFrom(String addstr, Object name) {
try {
if (addstr.indexOf("@") < 0) { if (addstr.indexOf("@") < 0) {
throw new AddressException(); throw new AddressException();
} }
@ -270,6 +287,10 @@ public class MailObject extends ScriptableObject implements Serializable {
} }
message.setFrom(address); message.setFrom(address);
} catch (Exception mx) {
System.err.println("Error in MailObject.setFrom(): "+mx);
setStatus(FROM);
}
} }
@ -282,8 +303,14 @@ public class MailObject extends ScriptableObject implements Serializable {
* @throws Exception ... * @throws Exception ...
* @throws AddressException ... * @throws AddressException ...
*/ */
public void setTo(String addstr, Object name) throws Exception { public void setTo(String addstr, Object name) {
try {
addRecipient(addstr, name, Message.RecipientType.TO); addRecipient(addstr, name, Message.RecipientType.TO);
} catch (Exception mx) {
System.err.println("Error in MailObject.setTo(): "+mx);
setStatus(TO);
}
} }
@ -296,8 +323,14 @@ public class MailObject extends ScriptableObject implements Serializable {
* @throws Exception ... * @throws Exception ...
* @throws AddressException ... * @throws AddressException ...
*/ */
public void addTo(String addstr, Object name) throws Exception { public void addTo(String addstr, Object name) {
try {
addRecipient(addstr, name, Message.RecipientType.TO); addRecipient(addstr, name, Message.RecipientType.TO);
} catch (Exception mx) {
System.err.println("Error in MailObject.addTO(): "+mx);
setStatus(TO);
}
} }
/** /**
@ -309,8 +342,13 @@ public class MailObject extends ScriptableObject implements Serializable {
* @throws Exception ... * @throws Exception ...
* @throws AddressException ... * @throws AddressException ...
*/ */
public void addCC(String addstr, Object name) throws Exception { public void addCC(String addstr, Object name) {
try {
addRecipient(addstr, name, Message.RecipientType.CC); addRecipient(addstr, name, Message.RecipientType.CC);
} catch (Exception mx) {
System.err.println("Error in MailObject.addCC(): "+mx);
setStatus(CC);
}
} }
/** /**
@ -322,8 +360,13 @@ public class MailObject extends ScriptableObject implements Serializable {
* @throws Exception ... * @throws Exception ...
* @throws AddressException ... * @throws AddressException ...
*/ */
public void addBCC(String addstr, Object name) throws Exception { public void addBCC(String addstr, Object name) {
try {
addRecipient(addstr, name, Message.RecipientType.BCC); addRecipient(addstr, name, Message.RecipientType.BCC);
} catch (Exception mx) {
System.err.println("Error in MailObject.addBCC(): "+mx);
setStatus(BCC);
}
} }
/** /**
@ -358,10 +401,13 @@ public class MailObject extends ScriptableObject implements Serializable {
/** /**
* Send the message. * Send the message.
*
* @throws Exception ...
*/ */
public void send() throws Exception { public void send() {
// only send message if everything's ok
if (status != OK) {
System.err.println("Error sending mail. Status="+status);
}
try {
if (buffer != null) { if (buffer != null) {
// if we also have a multipart body, add // if we also have a multipart body, add
// plain string as first part to it. // plain string as first part to it.
@ -381,5 +427,9 @@ public class MailObject extends ScriptableObject implements Serializable {
} }
Transport.send(message); Transport.send(message);
} catch (Exception mx) {
System.err.println("Error in MailObject.send(): "+mx);
setStatus(SEND);
}
} }
} }