001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *  http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied.  See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     */
019    
020    package org.apache.geronimo.javamail.transport.smtp;
021    
022    import java.io.InputStream;
023    
024    import javax.mail.MessagingException;
025    import javax.mail.Session;
026    import javax.mail.internet.MimeMessage;
027    
028    public class SMTPMessage extends MimeMessage {
029    
030        // never notify
031        public static final int NOTIFY_NEVER = -1;
032    
033        // notify of successful deliveries.
034        public static final int NOTIFY_SUCCESS = 1;
035    
036        // notify of delivery failures.
037        public static final int NOTIFY_FAILURE = 2;
038    
039        // notify of delivery delays
040        public static final int NOTIFY_DELAY = 4;
041    
042        // return full message with status notifications
043        public static final int RETURN_FULL = 1;
044    
045        // return only message headers with status notifications
046        public static final int RETURN_HDRS = 2;
047    
048        // support 8BitMime encodings
049        protected boolean allow8bitMIME = false;
050    
051        // a from address specified in the message envelope. Overrides other from
052        // sources.
053        protected String envelopeFrom = null;
054    
055        // an option string to append to the MAIL command on sending.
056        protected String mailExtension = null;
057    
058        // SMTP mail notification options if DSN is supported.
059        protected int notifyOptions = 0;
060    
061        // DSN return option notification values.
062        protected int returnOption = 0;
063    
064        // allow sending if some addresses give errors.
065        protected boolean sendPartial = false;
066    
067        // an RFC 2554 AUTH= value.
068        protected String submitter = null;
069    
070        /**
071         * Default (and normal) constructor for an SMTPMessage.
072         * 
073         * @param session
074         *            The hosting Javamail Session.
075         */
076        public SMTPMessage(Session session) {
077            // this is a simple one.
078            super(session);
079        }
080    
081        /**
082         * Construct an SMTPMessage instance by reading and parsing the data from
083         * the provided InputStream. The InputStream will be left positioned at the
084         * end of the message data on constructor completion.
085         * 
086         * @param session
087         *            The hosting Javamail Session.
088         */
089        public SMTPMessage(Session session, InputStream source) throws MessagingException {
090            // this is a simple one.
091            super(session, source);
092        }
093    
094        /**
095         * Construct an SMTPMimeMessage from another source MimeMessage object. The
096         * new object and the old object are independent of each other.
097         * 
098         * @param source
099         *            The source MimeMessage object.
100         */
101        public SMTPMessage(MimeMessage source) throws MessagingException {
102            super(source);
103        }
104    
105        /**
106         * Change the allow8BitMime attribute for the message.
107         * 
108         * @param a
109         *            The new setting.
110         */
111        public void setAllow8bitMIME(boolean a) {
112            allow8bitMIME = a;
113        }
114    
115        /**
116         * Retrieve the current 8bitMIME attribute.
117         * 
118         * @return The current attribute value.
119         */
120        public boolean getAllow8bitMIME() {
121            return allow8bitMIME;
122        }
123    
124        /**
125         * Change the envelopeFrom attribute for the message.
126         * 
127         * @param from
128         *            The new setting.
129         */
130        public void setEnvelopeFrom(String from) {
131            envelopeFrom = from;
132        }
133    
134        /**
135         * Retrieve the current evelopeFrom attribute.
136         * 
137         * @return The current attribute value.
138         */
139        public String getEnvelopeFrom() {
140            return envelopeFrom;
141        }
142    
143        /**
144         * Change the mailExtension attribute for the message.
145         * 
146         * @param e
147         *            The new setting.
148         */
149        public void setMailExtension(String e) {
150            mailExtension = e;
151        }
152    
153        /**
154         * Retrieve the current mailExtension attribute.
155         * 
156         * @return The current attribute value.
157         */
158        public String getMailExtension() {
159            return mailExtension;
160        }
161    
162        /**
163         * Change the notifyOptions attribute for the message.
164         * 
165         * @param options
166         *            The new setting.
167         */
168        public void setNotifyOptions(int options) {
169            notifyOptions = options;
170        }
171    
172        /**
173         * Retrieve the current notifyOptions attribute.
174         * 
175         * @return The current attribute value.
176         */
177        public int getNotifyOptions() {
178            return notifyOptions;
179        }
180    
181        /**
182         * Change the returnOptions attribute for the message.
183         * 
184         * @param option
185         *            The new setting.
186         */
187        public void setReturnOption(int option) {
188            returnOption = option;
189        }
190    
191        /**
192         * Retrieve the current returnOption attribute.
193         * 
194         * @return The current attribute value.
195         */
196        public int getReturnOption() {
197            return returnOption;
198        }
199    
200        /**
201         * Change the sendPartial attribute for the message.
202         * 
203         * @param a
204         *            The new setting.
205         */
206        public void setSendPartial(boolean a) {
207            sendPartial = a;
208        }
209    
210        /**
211         * Retrieve the current sendPartial attribute.
212         * 
213         * @return The current attribute value.
214         */
215        public boolean getSendPartial() {
216            return sendPartial;
217        }
218    
219        /**
220         * Change the submitter attribute for the message.
221         * 
222         * @param s
223         *            The new setting.
224         */
225        public void setSubmitter(String s) {
226            submitter = s;
227        }
228    
229        /**
230         * Retrieve the current submitter attribute.
231         * 
232         * @return The current attribute value.
233         */
234        public String getSubmitter() {
235            return submitter;
236        }
237    }