Gabriel Petrovay has proposed merging lp:~zorba-coders/zorba/email_sausalito_fixes_r2651_and_r2676 into lp:zorba/email-module.
Requested reviews: Gabriel Petrovay (gabipetrovay) David Graf (davidagraf) For more details, see: https://code.launchpad.net/~zorba-coders/zorba/email_sausalito_fixes_r2651_and_r2676/+merge/88236 Adds a couple of fixes from Sausalito r2651 and r2676 -- https://code.launchpad.net/~zorba-coders/zorba/email_sausalito_fixes_r2651_and_r2676/+merge/88236 Your team Zorba Coders is subscribed to branch lp:zorba/email-module.
=== added file 'examples/Queries/imap/mimetypes_example.xq' --- examples/Queries/imap/mimetypes_example.xq 1970-01-01 00:00:00 +0000 +++ examples/Queries/imap/mimetypes_example.xq 2012-01-11 16:58:27 +0000 @@ -0,0 +1,44 @@ +(: + : This should issue 4 + :) + +import schema namespace email = 'http://www.zorba-xquery.com/modules/email'; + +let $messages := + for $type in ("application/3gpp-ims+xml","application/cals-1840","application/pkcs7-signature","application/vnd.openxmlformats-officedocument.presentationml.comments+xml") + return + fn:validate { + <email:message xmlns:email="http://www.zorba-xquery.com/modules/email/email"> + <envelope> + <date>2010-11-26T15:50:39</date> + <from> + <email>zorba.smtp.sen...@gmail.com</email> + </from> + <sender> + <email>zorba.smtp.sen...@gmail.com</email> + </sender> + <replyTo> + <email>zorba.smtp.sen...@gmail.com</email> + </replyTo> + <subject>RegexTest</subject> + <recipient> + <to> + <email>imapt...@28msec.com</email> + </to> + </recipient> + <messageId><4ea85e91.679e440a.0f97.2...@mx.google.com></messageId> + <flags> + <seen/> + </flags> + </envelope> + <mimeVersion>1.0</mimeVersion> + <body> + <multipart contentType="multipart/mixed" charset="us-ascii" contentTransferEncoding="ENC7BIT"> + <content contentType="text/plain" charset="us-ascii" contentTransferEncoding="ENCQUOTEDPRINTABLE">=0A Zorba really rocks. =0A </content> + <content contentType="{$type}" charset="us-ascii" contentTransferEncoding="ENCBASE64" contentDisposition="the-truth.gif">some content</content> + </multipart> + </body> + </email:message> + } +return + fn:count($messages) === modified file 'src/com/zorba-xquery/www/modules/email/email.xsd' --- src/com/zorba-xquery/www/modules/email/email.xsd 2011-09-14 07:34:28 +0000 +++ src/com/zorba-xquery/www/modules/email/email.xsd 2012-01-11 16:58:27 +0000 @@ -127,7 +127,7 @@ <!-- definition of simple elements --> <simpleType name="contentTypeValue"> <restriction base="string"> - <pattern value="[a-zA-Z]+/[a-zA-Z]+((\-|\+|\.)[a-zA-Z]+)*"/> + <pattern value="[a-zA-Z]+/[a-zA-Z0-9\-\+\.]+"/> </restriction> </simpleType> @@ -146,7 +146,7 @@ <attribute name="contentDisposition" type="string"/> <attribute name="contentDisposition-filename" type="string"/> <attribute name="contentDisposition-modification-date" type="dateTime"/> - <attribute name="content-id" type="string" /> + <attribute name="content-id" type="string"/> </extension> </simpleContent> </complexType> @@ -155,10 +155,11 @@ <choice maxOccurs="unbounded"> <element name="content" type="tns:contentType" minOccurs="1"/> <element name="multipart" type="tns:multipartType" minOccurs="1"/> - </choice> + </choice> <attribute name="contentType" type="tns:contentTypeValue"/> <attribute name="charset" type="string" default="us-ascii"/> <attribute name="contentTransferEncoding" type="tns:cteType" default="ENC7BIT"/> + <attribute name="contentDisposition" type="string"/> </complexType> <complexType name="bodyTypeChoice"> === modified file 'src/com/zorba-xquery/www/modules/email/imap.xq.src/imap_function.cpp' --- src/com/zorba-xquery/www/modules/email/imap.xq.src/imap_function.cpp 2011-10-05 13:00:46 +0000 +++ src/com/zorba-xquery/www/modules/email/imap.xq.src/imap_function.cpp 2012-01-11 16:58:27 +0000 @@ -176,7 +176,7 @@ // then push MM // build up map for Months - std::string lMonths = "JanFebMarAprMayJunJulAugSepOctNovDez"; + std::string lMonths = "JanFebMarAprMayJunJulAugSepOctNovDec"; size_t lMonthNumber = lMonths.find(lTokens[2]); // if the month was not found, were really in trouble! if (lMonthNumber == std::string::npos) { @@ -633,7 +633,6 @@ lBodies.erase(lBodies.begin()); // get different attributes that we will need in any case, regardless if this is a content or multipart item std::string lContentType = getContentType(lCurrentBody->type, lCurrentBody->subtype); - std::string lEncoding = getEncoding(lCurrentBody->encoding); std::string lContentDisposition = ""; if (lCurrentBody->disposition.type != NIL) { lContentDisposition = cpystr(lCurrentBody->disposition.type); @@ -680,15 +679,29 @@ lParam = lParam->next; } + std::string lTransferEncodingDecoded; + unsigned short lEncoding = lCurrentBody->encoding; + // decode the body according the transfer encoding if it is quoted-printable + decodeTextualTransferEncoding(lBodyContent, lContentType, lEncoding, lTransferEncodingDecoded); + // decode the body according to the charset - std::string lDecoded; - toUtf8(lBodyContent, lCharset, lDecoded); + std::string lCharsetDecoded; + toUtf8(lTransferEncodingDecoded, lCharset, lCharsetDecoded); - createContentNode(lCurrentParent, lDecoded, lContentType, "us-ascii", lEncoding, lContentDisposition, lContentDispositionFilename, lContentDispositionModificationDate, lContentId); + createContentNode(lCurrentParent, lCharsetDecoded, lContentType, + "utf-8", getEncoding(lEncoding), lContentDisposition, + lContentDispositionFilename, lContentDispositionModificationDate, + lContentId); } else { - lMultipartParent = theModule->getItemFactory()->createElementNode(lCurrentParent, lMultipartParentName, lMultipartParentType, false, false, ns_binding); - createContentTypeAttributes(lMultipartParent, lContentType, "us-ascii", lEncoding, lContentDisposition, lContentDispositionFilename, lContentDispositionModificationDate); + lMultipartParent = theModule->getItemFactory()->createElementNode( + lCurrentParent, lMultipartParentName, lMultipartParentType, false, + false, ns_binding); + + createContentTypeAttributes(lMultipartParent, lContentType, "utf-8", + getEncoding(lCurrentBody->encoding), lContentDisposition, + lContentDispositionFilename, lContentDispositionModificationDate); + PART* lPart = lCurrentBody->nested.part; lBodies.insert(lBodies.begin(), &lPart->body); lParents.insert(lParents.begin(), lMultipartParent); @@ -833,5 +846,35 @@ } +void +ImapFunction::decodeTextualTransferEncoding( + const std::string& aValue, + const std::string& aContentType, + unsigned short& aEncoding, + std::string& aResult) const +{ + if (aEncoding == ENCQUOTEDPRINTABLE) { + unsigned long lNewLength; + void* lNewData = rfc822_qprint((unsigned char*)aValue.c_str(), aValue.length(), &lNewLength); + aResult = std::string((char *)lNewData, lNewLength); + fs_give(&lNewData); + aEncoding = ENC8BIT; + } + else if (aEncoding == ENCBASE64 && + ( + aContentType.find("text") != std::string::npos + || aContentType.find("xml") != std::string::npos + )) { + unsigned long lNewLength; + void* lNewData = rfc822_base64((unsigned char*)aValue.c_str(), aValue.length(), &lNewLength); + aResult = std::string((char *)lNewData, lNewLength); + fs_give(&lNewData); + aEncoding = ENC8BIT; + } + else { + aResult = aValue; + } +} + } /* namespace emailmodule */ } /* namespace zorba */ === modified file 'src/com/zorba-xquery/www/modules/email/imap.xq.src/imap_function.h' --- src/com/zorba-xquery/www/modules/email/imap.xq.src/imap_function.h 2011-10-05 13:00:46 +0000 +++ src/com/zorba-xquery/www/modules/email/imap.xq.src/imap_function.h 2012-01-11 16:58:27 +0000 @@ -34,7 +34,7 @@ { protected: const ImapModule* theModule; - static const char* SCHEMA_NAMESPACE; + static const char* SCHEMA_NAMESPACE; void raiseImapError( @@ -149,16 +149,22 @@ void getMessage( - Item& aParent, - const std::string& aHostName, - const std::string& aUserName, - const std::string& aPassword, - const std::string& aMailbox, - const unsigned long aMessageNumber, - const bool aUid, + Item& aParent, + const std::string& aHostName, + const std::string& aUserName, + const std::string& aPassword, + const std::string& aMailbox, + const unsigned long aMessageNumber, + const bool aUid, const bool aOnlyEnvelope) const; void + decodeTextualTransferEncoding(const std::string& aValue, + const std::string& aContentType, + unsigned short& aEncoding, + std::string& aResult) const; + + void toUtf8( const std::string& value, const char* fromCharset, @@ -167,6 +173,9 @@ void checkStatus(UErrorCode aStatus) const; + /** + * Decodes header of an email, e.g. the subject. + */ void decodeHeader( const std::string& value,
-- Mailing list: https://launchpad.net/~zorba-coders Post to : zorba-coders@lists.launchpad.net Unsubscribe : https://launchpad.net/~zorba-coders More help : https://help.launchpad.net/ListHelp