Login  Register

[jira] Commented: (OFBIZ-70) EmailServices.storeIncomingEmail(EmailServices.java:643)-- String index out of range: -1

Posted by Nicolas Malin (Jira) on Jul 30, 2006; 3:05am
URL: http://ofbiz.116.s1.nabble.com/jira-Created-OFBIZ-70-EmailServices-storeIncomingEmail-EmailServices-java-643-String-index-out-of-ra1-tp169170p169175.html

    [ http://issues.apache.org/jira/browse/OFBIZ-70?page=comments#action_12424340 ]
           
BJ Freeman commented on OFBIZ-70:
---------------------------------

It appears that there is differnt handling of the IMAP and POP# email content.


Also I believe some of these if not all are effecting the service.

From
http://java.sun.com/products/javamail/FAQ.html

Q: The IMAP provider seems to lose data when I fetch messages with large attachments.
A: This is due to bugs in the partial fetch implementation of your IMAP server. To workaround this server bug, set the "mail.imap.partialfetch" property to "false". Refer to NOTES.txt from the JavaMail package for more information.

Q: Why do I get the UnsupportedDataTypeException when I invoke getContent() on a bodypart?
A: The getContent() method returns a Java object that represents the bodypart content. For this to work, a JAF DataContentHandler corresponding to the content's MIME type must be registered. Otherwise, the UnsupportedDataTypeException will be thrown. In this case, you can use the getInputStream() method to retrieve the content as a stream of bytes. See the JAF docs for details on how to create and register your own DataContentHandlers.

Q: Why do I get the UnsupportedEncodingException when I invoke getContent() on a bodypart that contains text data?
A: Textual bodyparts (i.e., bodyparts whose type is "text/plain", "text/html", or "text/xml") return Unicode String objects when getContent() is used. Typically, such bodyparts internally hold their textual data in some non Unicode charset. JavaMail (through the corresponding DataContentHandler) attempts to convert that data into a Unicode string. The underlying JDK's charset converters are used to do this. If the JDK does not support a particular charset, then the UnsupportedEncodingException is thrown. In this case, you can use the getInputStream() method to retrieve the content as a stream of bytes. Example:
 String s;
    if (part.isMimeType("text/plain")) {
        try {
            s = part.getContent();
        } catch (UnsupportedEncodingException uex) {
            InputStream is = part.getInputStream();
            /*
             * Read the input stream into a byte array.
             * Choose a charset in some heuristic manner, use
             * that charset in the java.lang.String constructor
             * to convert the byte array into a String.
             */
            s = convert_to_string(is);
        } catch (Exception ex) {
            // Handle other exceptions appropriately
        }
    }




> EmailServices.storeIncomingEmail(EmailServices.java:643)-- String index out of range: -1
> ----------------------------------------------------------------------------------------
>
>                 Key: OFBIZ-70
>                 URL: http://issues.apache.org/jira/browse/OFBIZ-70
>             Project: OFBiz (The Open for Business Project)
>          Issue Type: Bug
>          Components: content
>            Reporter: BJ Freeman
>
>  46701852[   ServiceMcaAction.java:69 :ERROR] String index out of range: -1
> 346702033[      EmailServices.java:747:ERROR]
> ---- runtime exception report --------------------------------------------------
> Exception: java.lang.StringIndexOutOfBoundsException
> Message: String index out of range: -1
> ---- stack trace ---------------------------------------------------------------
> java.lang.StringIndexOutOfBoundsException: String index out of range: -1
> java.lang.String.substring(String.java:1444)
> com.businessesnetwork.communications.EmailServices.storeIncomingEmail(EmailServices.java:643)
> sun.reflect.GeneratedMethodAccessor195.invoke(Unknown Source)
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> java.lang.reflect.Method.invoke(Method.java:324)
>  l       int idx = contentTypeRaw.indexOf(";");
>  ine 643              contentType = contentTypeRaw.substring(0, idx);
> email being evaluated
> Content-Type: text/plain
> Content-Disposition: inline
> Content-Transfer-Encoding: 7bit
> MIME-Version: 1.0
> I think the indexof for a semicoln will  set idx to null
> so line 643 fails.
> should test for null then
> contentType = contentTypeRaw;

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira