cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Davanum Srinivas <d...@yahoo.com>
Subject Re: mail/sendmail processors code submission
Date Wed, 18 Apr 2001 15:09:10 GMT
Thanks Bala. It would definitely be great if you could send us some samples and documentation.


-- dims

--- Bala Sambandam <bala@idanim.com> wrote:
> Hello Dims,
> 
> Well, I never wrote any unit testcases, but I can send you the application that I wrote
with it;
> however, it's integrated in with the rest of my site so it makes esql calls on a schema
that the
> tester will not have.  I could include instructions on how to hardcode data whereever
these esql
> calls exist, if this is acceptable.  If you would like real unit testcases instead, then
point
> me to some requirements or samples of these testcases and documentation on the testcase
harness,
> and I will see what I can do.
> 
> thanks,
> Bala
> 
> > Davanum Srinivas <dims@yahoo.com> wrote:
> > Bala,
> > Can you send us some samples used to test both mail.xsl and sendmail.xsl? Then i
will be able
> to
> > test it before checking it in.
> > Thanks,
> > dims
> > --- Bala Sambandam <bala@idanim.com> wrote:
> > > Hello,
> > > 
> > > I've written a web frontend for IMAP/Sendmail using the mail.xsl and 
> > > sendmail.xsl processors, and I'm including the modifications that I had 
> > > to make to these processors to get as far as I've gotten with the 
> > > application.
> > > 
> > > mail.xsl.diff is diff -w -u against version 1.6
> > > sendmail.xsl.diff is diff -w -u against version 1.9
> > > 
> > > If any additional info is needed for either file, then let me know by 
> > > sending mail to me directly, as I will likely unsub from the list.
> > > 
> > > The modifications that I made to mail.xsl require HTML Tidy for the 
> > > interpretation of badly formed HTML messages as XML fragments; 
> > > otherwise, badly formed HTML messages are interpretted as plain text.  
> > > Well formed HTML messages are interpreted as XML fragments without the 
> > > need of HTML Tidy.
> > > 
> > > thanks,
> > > Bala
> > > > --- mail.xsl	Tue Apr 17 17:25:12 2001
> > > +++ idanim/intranet/src/org/apache/cocoon/processor/xsp/library/mail/mail.xsl
Tue Apr 17
> > > 15:41:21 2001
> > > @@ -55,6 +55,7 @@
> > >  
> > >   <author>Donald A. Ball Jr.</author>
> > >   <author>Ugo Cei</author>
> > > + <contributor>Bala Sambandam, Idanim Solutions Inc.</contributor>
> > >   <version>1.2</version>
> > >  -->
> > >  <xsl:stylesheet
> > > @@ -68,6 +69,7 @@
> > >   <xsl:copy>
> > >    <xsl:apply-templates select="@*"/>
> > >    <xsp:structure>
> > > +				<xsp:include>java.lang.reflect.Method</xsp:include>
> > >     <xsp:include>javax.mail.Session</xsp:include>
> > >     <xsp:include>javax.mail.Store</xsp:include>
> > >     <xsp:include>javax.mail.Folder</xsp:include>
> > > @@ -76,13 +78,32 @@
> > >     <xsp:include>javax.mail.Part</xsp:include>
> > >     <xsp:include>javax.mail.Multipart</xsp:include>
> > >     <xsp:include>javax.mail.Flags</xsp:include>
> > > +				<xsp:include>javax.mail.MessagingException</xsp:include>
> > >     <xsp:include>javax.mail.internet.MimeMessage</xsp:include>
> > >     <xsp:include>javax.mail.internet.MimePart</xsp:include>
> > >     <xsp:include>javax.mail.internet.InternetAddress</xsp:include>
> > > +				<xsp:include>javax.mail.search.MessageIDTerm</xsp:include>
> > > +				<xsp:include>javax.mail.search.FromStringTerm</xsp:include>
> > > +				<xsp:include>javax.mail.search.SearchTerm</xsp:include>
> > > +				<xsp:include>javax.mail.search.OrTerm</xsp:include>
> > >     <xsp:include>java.text.DateFormat</xsp:include>
> > >    </xsp:structure>
> > >    <xsl:apply-templates/>
> > > +
> > >    <xsp:logic>
> > > +
> > > +				/**
> > > +				 * This method process the message content.
> > > +				 *
> > > +				 * @param request The servlet request.
> > > +				 * @param response The servlet response.
> > > +				 * @param document The xsp document.
> > > +				 * @param xspParentNode The xsp parent node pass through.
> > > +				 * @param xspCurrentNode The xsp current node pass through.
> > > +				 * @param xspNodeStack The xsp node stack pass through.
> > > +				 * @param session The servlet session.
> > > +				 * @param part The the message or submessage (on recursion).
> > > +				 */
> > >     void _mail_process_content(
> > >      HttpServletRequest request,
> > >      HttpServletResponse response,
> > > @@ -91,23 +112,199 @@
> > >      Node xspCurrentNode,
> > >      Stack xspNodeStack,
> > >      HttpSession session,
> > > -    MimePart part) throws Exception {
> > > +						MimePart part) throws MessagingException, IOException {
> > > +	
> > >    if (part.isMimeType("text/plain")) {
> > > -   <xsp:content><xsp:expr>(String)part.getContent()</xsp:expr></xsp:content>
> > > +
> > > +						// just return the plain text
> > > +						<xsp:content>
> > > +							<xsp:expr>(String)part.getContent()</xsp:expr>
> > > +						</xsp:content>
> > > +
> > > +					} else if (part.isMimeType("text/html")) {
> > > +
> > > +						try {
> > > +
> > > +							<xsp:content>
> > > +								<xsp:expr>
> > > +									// try to parse the html as xml
> > > +									// who knows it might be well formed
> > > +									xspParser.parse(new InputSource(new StringReader(
> > > +										(String) part.getContent()))).getDocumentElement()
> > > +								</xsp:expr>
> > > +							</xsp:content>
> > > +
> > > +						} catch (Throwable e) {
> > > +
> > > +							// more than likely something will go wrong
> > > +
> > > +							e.printStackTrace();
> > > +
> > > +							try {
> > > +
> > > +								// try to load the HTML Tidy class to
> > > +								// clean the HTML up a bit
> > > +								Class _mail_tidy_class =
> > > +									Class.forName("org.w3c.tidy.Tidy");
> > > +								Object _mail_tidy = _mail_tidy_class.newInstance();
> > > +
> > > +								// find the right method
> > > +								Class[] _mail_params = {
> > > +									InputStream.class, OutputStream.class
> > > +								};
> > > +								Method _mail_method =
> > > +									_mail_tidy_class.getMethod("parseDOM", _mail_params);
> > > +
> > > +								// invoke the method
> > > +								Object[] _mail_args = {
> > > +									new ByteArrayInputStream(
> > > +										((String) part.getContent()).getBytes()),
> > > +									null
> > > +								};
> > > +								Document _mail_html_doc = (Document)
> > > +										_mail_method.invoke(
> > > +											_mail_tidy, _mail_args);
> > > +
> > > +								// return the HTML as an XML fragment
> > > +								<xsp:content>
> > > +									<xsp:expr>
> > > +										_mail_html_doc.getDocumentElement()
> > > +									</xsp:expr>
> > > +								</xsp:content>
> > > +
> > > +							} catch (Throwable e1) {
> > > +
> > > +								// if all else fails then just return it
> > > +								// as if it was plain text
> > > +								e1.printStackTrace();
> > > +								<xsp:content>
> > > +									<xsp:expr>(String) part.getContent()</xsp:expr>
> > > +								</xsp:content>
> > > +
> > > +							}
> > > +						}
> > > +
> > >    } else if (part.isMimeType("message/rfc822")) {
> > > -   <xsp:content><rfc822><xsp:logic>
> > > -  
> > >
> >
>
_mail_process_content(request,response,document,xspParentNode,xspCurrentNode,xspNodeStack,session,(MimePart)part.getContent());
> > > -   </xsp:logic></rfc822></xsp:content>
> > > +
> > > +						<xsp:content>
> > > +							<rfc822>
> > > +								<xsp:logic>
> > > +									_mail_process_content(
> > > +										request,
> > > +										response,
> > > +										document,
> > > +										xspParentNode,
> > > +										xspCurrentNode,
> > > +										xspNodeStack,
> > > +										session,
> > > +										(MimePart)part.getContent());
> > > +								</xsp:logic>
> > > +							</rfc822>
> > > +						</xsp:content>
> > > +
> > >    } else if (part.isMimeType("multipart/*")) {
> > > +
> > > +						// recursively process each subpart
> > > +
> > >     Multipart multipart = (Multipart)part.getContent();
> > >     int count = multipart.getCount();
> 
=== message truncated ===


=====
Davanum Srinivas, JNI-FAQ Manager
http://www.jGuru.com/faq/JNI

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message