001: /*
002: * Copyright 2002-2005 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.mail.javamail;
018:
019: import java.util.Date;
020:
021: import javax.mail.MessagingException;
022: import javax.mail.internet.MimeMessage;
023:
024: import org.springframework.mail.MailMessage;
025: import org.springframework.mail.MailParseException;
026:
027: /**
028: * Implementation of the MailMessage interface for a JavaMail MIME message,
029: * to let message population code interact with a simple message or a MIME
030: * message through a common interface.
031: *
032: * <p>Uses a MimeMessageHelper underneath. Can either be created with a
033: * MimeMessageHelper instance or with a JavaMail MimeMessage instance.
034: *
035: * @author Juergen Hoeller
036: * @since 1.1.5
037: * @see MimeMessageHelper
038: * @see javax.mail.internet.MimeMessage
039: */
040: public class MimeMailMessage implements MailMessage {
041:
042: private final MimeMessageHelper helper;
043:
044: /**
045: * Create a new MimeMailMessage based on the given MimeMessageHelper.
046: * @param mimeMessageHelper the MimeMessageHelper
047: */
048: public MimeMailMessage(MimeMessageHelper mimeMessageHelper) {
049: this .helper = mimeMessageHelper;
050: }
051:
052: /**
053: * Create a new MimeMailMessage based on the given JavaMail MimeMessage.
054: * @param mimeMessage the JavaMail MimeMessage
055: */
056: public MimeMailMessage(MimeMessage mimeMessage) {
057: this .helper = new MimeMessageHelper(mimeMessage);
058: }
059:
060: /**
061: * Return the MimeMessageHelper that this MimeMailMessage is based on.
062: */
063: public final MimeMessageHelper getMimeMessageHelper() {
064: return this .helper;
065: }
066:
067: /**
068: * Return the JavaMail MimeMessage that this MimeMailMessage is based on.
069: */
070: public final MimeMessage getMimeMessage() {
071: return this .helper.getMimeMessage();
072: }
073:
074: public void setFrom(String from) throws MailParseException {
075: try {
076: this .helper.setFrom(from);
077: } catch (MessagingException ex) {
078: throw new MailParseException(ex);
079: }
080: }
081:
082: public void setReplyTo(String replyTo) throws MailParseException {
083: try {
084: this .helper.setReplyTo(replyTo);
085: } catch (MessagingException ex) {
086: throw new MailParseException(ex);
087: }
088: }
089:
090: public void setTo(String to) throws MailParseException {
091: try {
092: this .helper.setTo(to);
093: } catch (MessagingException ex) {
094: throw new MailParseException(ex);
095: }
096: }
097:
098: public void setTo(String[] to) throws MailParseException {
099: try {
100: this .helper.setTo(to);
101: } catch (MessagingException ex) {
102: throw new MailParseException(ex);
103: }
104: }
105:
106: public void setCc(String cc) throws MailParseException {
107: try {
108: this .helper.setCc(cc);
109: } catch (MessagingException ex) {
110: throw new MailParseException(ex);
111: }
112: }
113:
114: public void setCc(String[] cc) throws MailParseException {
115: try {
116: this .helper.setCc(cc);
117: } catch (MessagingException ex) {
118: throw new MailParseException(ex);
119: }
120: }
121:
122: public void setBcc(String bcc) throws MailParseException {
123: try {
124: this .helper.setBcc(bcc);
125: } catch (MessagingException ex) {
126: throw new MailParseException(ex);
127: }
128: }
129:
130: public void setBcc(String[] bcc) throws MailParseException {
131: try {
132: this .helper.setBcc(bcc);
133: } catch (MessagingException ex) {
134: throw new MailParseException(ex);
135: }
136: }
137:
138: public void setSentDate(Date sentDate) throws MailParseException {
139: try {
140: this .helper.setSentDate(sentDate);
141: } catch (MessagingException ex) {
142: throw new MailParseException(ex);
143: }
144: }
145:
146: public void setSubject(String subject) throws MailParseException {
147: try {
148: this .helper.setSubject(subject);
149: } catch (MessagingException ex) {
150: throw new MailParseException(ex);
151: }
152: }
153:
154: public void setText(String text) throws MailParseException {
155: try {
156: this .helper.setText(text);
157: } catch (MessagingException ex) {
158: throw new MailParseException(ex);
159: }
160: }
161:
162: }
|