Source Code Cross Referenced for PureMIME.java in  » Web-Mail » oyster » org » enhydra » oyster » mail » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Mail » oyster » org.enhydra.oyster.mail 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Title:        Oyster Project
003:         * Description:  S/MIME email sending capabilities
004:         * @Author       Vladan Obradovic, Vladimir Radisic
005:         * @Version      2.1.6
006:         */
007:
008:        package org.enhydra.oyster.mail;
009:
010:        import org.enhydra.oyster.smime.BaseSMIMEObject;
011:        import org.enhydra.oyster.exception.SMIMEException;
012:        import javax.mail.Multipart;
013:        import javax.mail.internet.MimeMessage;
014:        import javax.mail.internet.MimeBodyPart;
015:        import javax.mail.internet.MimeMultipart;
016:        import java.util.SimpleTimeZone;
017:        import java.util.GregorianCalendar;
018:
019:        /**
020:         * PureMIME class is used for creating and sending pure (clear) MIME message
021:         * (withouth any cryptographic posibilities). Initialization, creating and sending
022:         * of pure (clear) MIME message has the same functionalities as S/MIME type of
023:         * message.
024:         */
025:        public class PureMIME extends BaseSMIMEObject {
026:
027:            /**
028:             * Initializes the JavaMail session for SMTP and the MimeMessage object for message
029:             * which will be sent. Dynamically loads the BC and SUN provider necessary for
030:             * cryptography processing. This constructor is used for creating message with
031:             * text/plain content. For creating html formated content (text/html), other
032:             * constructor should be used in combination with one of setContent methods.
033:             * Note that after using this constructor setContent method can be used only
034:             * if "content" argument of constructor was given as null, otherwise setContent
035:             * method can't be used because content is already set as text/plain.
036:             * @param smtpHost name of SMTP host used for sending email
037:             * @param fromAddress email address of sender (FROM field in email header)
038:             * @param subject subject of email (SUBJECT field in email header). This
039:             * argument can be null, but email message will be sent withouth SUBJECT.
040:             * @param content text/plain content of email message. This argument can be
041:             * null, but later one of setContent() methods or one of addAttachment()
042:             * methods should be called
043:             * @param charset character set for passed subject and content. The given
044:             * Unicode string will be charset-encoded using the specified charset. The
045:             * charset is also used to set the "charset" parameter. For example German
046:             * letters should be encoded by usage of 'ISO-8859-1' charset. If charset
047:             * parameter is null and subject or content contains non US-ASCII characters,
048:             * it will be encoded using the platform's default charset.
049:             * @exception SMIMEException if smtpHost or fromAddress parameters are null.
050:             * Also, it can be caused by non SMIMEException which is MessagingException.
051:             */
052:            public PureMIME(String smtpHost, String fromAddress,
053:                    String subject, String content, String charset)
054:                    throws SMIMEException {
055:                super (smtpHost, fromAddress, subject, content, charset);
056:            }
057:
058:            /**
059:             * Initializes the JavaMail session for SMTP and the MimeMessage object for message
060:             * which will be sent. Dynamically loads the BC and SUN provider necessary for
061:             * cryptography processing. This constructor does not create content of message
062:             * and it can be set later with one of setContent methods. Also, message can be
063:             * left withouth content, but then at least one attachement must be added.
064:             * @param smtpHost name of SMTP host used for sending email
065:             * @param fromAddress email address of sender (FROM field in email header)
066:             * @param subject subject of email (SUBJECT field in email header). This
067:             * argument can be null, but email message will be sent withouth SUBJECT.
068:             * @param charset character set for passed subject and content. The given
069:             * Unicode string will be charset-encoded using the specified charset. The
070:             * charset is also used to set the "charset" parameter. For example German
071:             * letters should be encoded by usage of 'ISO-8859-1' charset. If charset
072:             * parameter is null and subject or content contains non US-ASCII characters,
073:             * it will be encoded using the platform's default charset.
074:             * @exception SMIMEException if smtpHost or fromAddress parameters are null.
075:             * Also, it can be caused by non SMIMEException which is MessagingException.
076:             */
077:            public PureMIME(String smtpHost, String fromAddress,
078:                    String subject, String charset) throws SMIMEException {
079:                super (smtpHost, fromAddress, subject, null, charset);
080:            }
081:
082:            /**
083:             * Construction of message with external prepared MimeMessage object. Usage of
084:             * this constructor disables usage of setContent() and addAttachment() methods.
085:             * Also, all recipients (TO, CC or BCC type) must be declared again via
086:             * setRecipient() method, even if they were previously set. Be very carefull
087:             * with usage of this constructor because all MimeBodyPart objects and
088:             * MimeMultipart objects used in construction of given MimeMessage object,
089:             * must have correct defined Content header arguments, and contents. Contents
090:             * must be formed in format which can be recognised and appropriate interpreted
091:             * in the process of sending mail. If there is any special content object
092:             * added to MimeBodyPart object or MimeMultipart object, the appropriate
093:             * DataContent handler must be created for that object and set to corresponding
094:             * BodyPart.
095:             * @param mimeMessage external created MimeMessage object
096:             * @exception SMIMEException if smtpHost or fromAddress parameter is null.
097:             * Also, it can be caused by non SMIMEException which is MessagingException.
098:             */
099:            public PureMIME(MimeMessage mimeMessage) throws SMIMEException {
100:                super (mimeMessage);
101:            }
102:
103:            /**
104:             * Adds recipient email address and type. At least one recipient must be declared
105:             * as TO type.
106:             * @param recipientAddress email address of recipent (fields TO or CC or BCC
107:             * in email message header)
108:             * @param type should be TO, CC or BCC.
109:             * @exception SMIMEException if type of addressing of the messages is not TO, CC,
110:             * or BCC. Also it can be caused by non SMIMEException which is MessagingException.
111:             */
112:            public void addRecipient(String recipientAddress, String type)
113:                    throws SMIMEException {
114:                super .addRecipient(recipientAddress, type, null);
115:            }
116:
117:            /**
118:             * Creates and composes the message.
119:             * @exception SMIMEException if one of recipients is not declared as TO
120:             * recipient. Also, it can be caused by non SMIMEException which can be one of
121:             * the following: MessagingException, or IOException.
122:             */
123:            public void composeMessage() throws SMIMEException {
124:                try {
125:                    if (super .indicatorTo != true)
126:                        throw new SMIMEException(1043);
127:
128:                    if (!super .externalMessagePresence) { // external MimeMessage object presence cheking
129:
130:                        if (super .contentPresence
131:                                & super .bodyPartArray.size() == 1) { // message contains only content
132:                            if (super .bodyPartArray.elementAt(0) instanceof  MimeBodyPart) { // text/plain message
133:                                MimeBodyPart contentBody = (MimeBodyPart) super .bodyPartArray
134:                                        .elementAt(0);
135:                                super .message.setContent((String) contentBody
136:                                        .getContent(), contentBody
137:                                        .getContentType());
138:                                super .message
139:                                        .setDisposition(super .message.INLINE);
140:                            } else
141:                                // text/html message
142:                                super .message
143:                                        .setContent((MimeMultipart) super .bodyPartArray
144:                                                .elementAt(0));
145:                        } else if (super .bodyPartArray.size() != 0) {
146:                            Multipart mp = new MimeMultipart();
147:                            for (int i = 0; i != super .bodyPartArray.size(); i++) {
148:                                if (super .bodyPartArray.elementAt(i) instanceof  MimeMultipart) {
149:                                    MimeBodyPart forMulti = new MimeBodyPart();
150:                                    forMulti
151:                                            .setContent((MimeMultipart) super .bodyPartArray
152:                                                    .elementAt(i));
153:                                    mp.addBodyPart(forMulti);
154:                                } else
155:                                    mp
156:                                            .addBodyPart((MimeBodyPart) super .bodyPartArray
157:                                                    .elementAt(i));
158:                            }
159:                            super .message.setContent(mp);
160:                        } else
161:                            throw new SMIMEException(1044);
162:
163:                    }
164:
165:                    super .message.saveChanges();
166:                    super .message.saveChanges();
167:                    SimpleTimeZone tz = (SimpleTimeZone) SimpleTimeZone
168:                            .getDefault(); // Sets date and time
169:                    GregorianCalendar cal = new GregorianCalendar(tz);
170:                    super .message.setSentDate(cal.getTime());
171:
172:                    clean();
173:                } catch (Exception e) {
174:                    throw new SMIMEException(e);
175:                }
176:
177:            }
178:
179:            /**
180:             * Releases unnecessary memory
181:             */
182:            private void clean() {
183:                super .reset();
184:                System.gc(); // Calling garbage collector
185:            }
186:
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.