I am not able to fetch size of a Attachment part using Javamail classes

Hi All,
I am using javamail classes to read mails from my email system.
the message i am reading is MIME Multipart and it has got attachments.
One of the attachment is 'application/smil' type.
I am not seeing its size properly but I am able to open the message correctly.
Is this a problem with rendering the message?
Any help would be greatly appreciated.
Thanks,
Amit

Hi,
Following is the code to render the part. It would be great if you can suggest something to modify and correct the problem.
As you said in your eariler reply, I am determining size by rendering attachment as one of the mime part.
Thanks,
Amit
     * Renders the specified part.
     * @param part part to be rendered
     * @return the modified message part
     * @throws MessagingException on JavaMail errors
     * @throws IOException on errors getting part contents
     * @throws RenderingException on problems rendering part content
    private Part renderPart(Part part)
            throws MessagingException, IOException, RenderingException {
        int partIndex = listSize;
        // Part has been displayed on another page and doesn't
        // need to be rendered.
        if (partIndex < state.getPartIndex()) {
            return null;
        } else if (partIndex != state.getPartIndex()) {
            state = new State(partIndex, "0");
        // Part is not renderable so return it.
        if (!part.isMimeType(MIME_TEXT) &&
            !part.isMimeType(MIME_DISPOSITION_NOTIFICATION)) {
            return part;
        String charset = null;
        try {
            part = MailUtils.repairContentTranscoding(part);
            ContentType type = getNormalizedContentType(part);
            if (logger.isDebugEnabled()) {
                logger.debug("Part[" + state.getPartIndex() +
                        "].ContentType: " + type);
            charset = type.getParameter("charset");
            if (charset != null && charset.length() > 0) {
                charset = MimeUtility.javaCharset(charset.trim());
                try {
                    if (!Charset.isSupported(charset)) {
                        logger.warn("Unsupported charset: \"" + charset + "\"");
                        charset = null; // Ignore, use default charset
                } catch (IllegalCharsetNameException icne) {
                    logger.warn("Illegal charset name: \"" + charset + "\"");
                    charset = null; // Ignore, use default charset
        } catch (MessagingException e) {
            if (logger.isDebugEnabled()) {
                logger.debug(e.getMessage(), e);
            charset = null; // Ignore, use default charset
        if (charset == null || charset.length() == 0) {
            if (state.getPartIndex() == 0) {
                // It is *Message body*
                // charset is not in Mime Header, so need to detect
                // the charset.
                charset = (String) setup.get("client.defaultEmailCharset");
            } else {
                // It is *Attachment*
                // charset is not in Mime Header, so need to detect
                // attached file charset.
                charset = (String) setup.get("client.defaultFileCharset");
        Folder folder = null;
        Part renderedPart = new MimeBodyPart();
        try {
            if (MailUtils.isOpenFolderRequired(this.message)) {
                folder = this.message.getFolder();
                if (! folder.isOpen()) {
                    folder.open(Folder.READ_ONLY);
            BufferedReader buf = new BufferedReader(
                    (charset != null && charset.length() > 0) ?
                    new InputStreamReader(part.getInputStream(), charset) :
                    new InputStreamReader(part.getInputStream()));
            StringBuffer stringbuf = new StringBuffer();
            String line = null;
             * Microsoft Outlook Express 6 sends Byte Order Mark
             * at the head of UTF-8 and UTF-7 stream. This BOM is displayed user
             * page as ? mark, so skip the BOM.
             * Note that charset is normalized by MimeUtility.javaCharset()
             * before here.
            if (charset != null &&
                    (charset.equals("UTF8") || charset.equals("utf-7")) &&
                    buf != null && buf.markSupported()) {
                buf.mark(10); // 10 byte is enough for read ahead limit.
                int c = buf.read();
                if (c != 0xfeff) { // Check BOM or not.
                    // Rewinding.
                    try {
                        buf.reset();
                    } catch (IOException e) {
                        // Buffer seems to be empty stream...
                        logger.debug("Reset exception: " + e.getMessage());
                } else {
                    logger.debug("Skip BOM char: " + c);
            if (maxSize > 0) {
                // It's hard to know exactly how much text to pass to the
                // renderer, since if this is text/html, it may contain HTML
                // tags that wouldn't be displayed on a WAP device, so just
                // get start position + twice the max size.
                int textSize = 2*maxSize;
                if (state != null) {
                    textSize += state.getPosition();
                while ((line = buf.readLine()) != null &&
                        stringbuf.length() < textSize) {
                    stringbuf.append(line).append("\n");
            } else {
                while ((line = buf.readLine()) != null) {
                    stringbuf.append(line).append("\n");
            String content = stringbuf.toString();
            String contentType = null;
            if (part.isMimeType(MIME_DISPOSITION_NOTIFICATION)) {
                contentType = MIME_TEXT_PLAIN;
            } else {
                contentType = getNormalizedContentType(part).toString();
            Renderer renderer  = null;
            if (maxSize != 0) {
                renderer = new TextRenderer(content, contentType,
                        setup, maxSize, state.getState());
            } else {
                renderer =
                        new TextRenderer(content, contentType, setup);
            if (renderer.hasNext()) {
                renderedPart.setText(renderer.next());
                renderedPart.setHeader(HEADER_CONTENT_TYPE, contentType);
            state = new State(partIndex, renderer.toString());
            if (maxSize != 0) {
                moreInCurrentPart = renderer.hasNext();
        } finally {
            if (folder != null && folder.isOpen()) {
                MailUtils.closeFolder(folder);
        return renderedPart;
    }

Similar Messages

  • Not able to fetch the data by Virtual Cube

    Hi Experts,
    My requirement is I need to fetch the data from Source System (From Data base table) by using Virtual Cube.
    What I have done is I have created Virtual Cube and created corresponding Function Module in Source System.
    That Function MOdule is working fine, if Data base table is small in Source System.But If data base table contains huge amount of data (millions of record), I am not able to fetch the data.
    Below is the code I have incorporated in my function module.
    c_th_mapping TYPE CL_RSDRV_EXTERNAL_IPROV_SRV=>TN_TH_IOBJ_FLD_MAPPING.
      DATA:
        l_s_map TYPE CL_RSDRV_EXTERNAL_IPROV_SRV=>TN_S_IOBJ_FLD_MAPPING.
      l_s_map-iobjnm = '0PARTNER'.
      l_s_map-fldnm  = 'PARTNER'.
      insert l_s_map into table l_th_mapping.
    create object l_r_srv
        exporting
           i_tablnm              = '/SAPSLL/V_BLBP'
          i_th_iobj_fld_mapping = l_th_mapping.
      l_r_srv->open_cursor(
        i_t_characteristics = characteristics[]
        i_t_keyfigures      = keyfigures[]
        i_t_selection       = selection[] ).
       l_r_srv->fetch_pack_data(
        importing
          e_t_data = data[] ).
      return-type = 'S'.
    In the above function Module,Internal table L_TH_MAPPING contains Info Objects from Virtual Cube and corresponding field from Underlying data base table.
    The problem where I am facing is, in the method FETCH_PACK_DATA, initially program is trying to fetch all the recordsfrom data base table to internal table.If Data base table so lagre, this logic is not working.
    So would you please help me how to handle these kind of issues.

    Hi Experts,
    My requirement is I need to fetch the data from Source System (From Data base table) by using Virtual Cube.
    What I have done is I have created Virtual Cube and created corresponding Function Module in Source System.
    That Function MOdule is working fine, if Data base table is small in Source System.But If data base table contains huge amount of data (millions of record), I am not able to fetch the data.
    Below is the code I have incorporated in my function module.
    c_th_mapping TYPE CL_RSDRV_EXTERNAL_IPROV_SRV=>TN_TH_IOBJ_FLD_MAPPING.
      DATA:
        l_s_map TYPE CL_RSDRV_EXTERNAL_IPROV_SRV=>TN_S_IOBJ_FLD_MAPPING.
      l_s_map-iobjnm = '0PARTNER'.
      l_s_map-fldnm  = 'PARTNER'.
      insert l_s_map into table l_th_mapping.
    create object l_r_srv
        exporting
           i_tablnm              = '/SAPSLL/V_BLBP'
          i_th_iobj_fld_mapping = l_th_mapping.
      l_r_srv->open_cursor(
        i_t_characteristics = characteristics[]
        i_t_keyfigures      = keyfigures[]
        i_t_selection       = selection[] ).
       l_r_srv->fetch_pack_data(
        importing
          e_t_data = data[] ).
      return-type = 'S'.
    In the above function Module,Internal table L_TH_MAPPING contains Info Objects from Virtual Cube and corresponding field from Underlying data base table.
    The problem where I am facing is, in the method FETCH_PACK_DATA, initially program is trying to fetch all the recordsfrom data base table to internal table.If Data base table so lagre, this logic is not working.
    So would you please help me how to handle these kind of issues.

  • Not able to fetch serial number in MFBF

    Hello,
    We are doing production booking through MFBF transaction and the serial number has to be enterred for each backflush.
    I want to check the serial number for validation, hence i am using user exit "ZXMRMU02" with customised code.
    I need to fetch plant and posting date from input screen and compare the posting month with serial number letter(month) if both are matching then only I should be able to do MFBF otherwise system should through an errror message that " posting is not in current month.
    The problem here is I am unable to fetch serial number from input screen (Program Name SAPLIPW1 & Screen Number 0200). however I am able to get Material , Posting dates, Plant.
    Please suggest how can we fetch serial number from input screen.
    when i go with field exit, I could fetch serial number but not able to fetch plant and posting dates which are in first screen.
    Thanks,
    Kumar

    Dear Kumar,
    As per Std SAP behaviour, You can't use Serial Number Management for Goods Movement with Backflushing.When you are setting Backflush indicator as 1 always backflush in Material master system will not allow you to maintain serial number profile in work scheduling view.
    Also go thr. SAP Note No. 317455 for more clarification about using serial numbers with backflushing.
    Hope this helps.
    Regards,
    Tejas
    Edited by: Tejas  Pujara on Apr 10, 2009 7:12 AM

  • Not able to fetch Roles for an user using HWF Identity XPath

    Hi,
    I am not able to fetch list of roles for a specific user using Human Workflow, Identity XPath. Using Script Activity when I am trying to call the menthod, the method doesn't return Role details. Any help will be appreciated...

    That's the rules of how it works.  A request has 1 request form per resource for all users on the request.  Those fields must all be marked as available in bulk as well to be viewed if you have more than 1 user on the request.  If you need to provide different values based on the user, your best option is pre-populate adapters on the process form and use logic to populate the fields.  You will not be able to manually provide different values during the request.
    -Kevin

  • Not able to fetch some network switches data in LMS 4.0

    Hi Experts,
     we have LMS 4.0 and we found one problem that some network switches data are not able to fetch with LMS.
    what could be the reason to happen this type of problem?
    please assist with best solution to resolve this issue..
    Suhas B.

    Hi,
    I am facing below problem
    Config Archival Status
    No. of Devices
    Successful
    48
    Failed
    1
    Partially Successful
    0
    Total
    1345
    Configuration Never Collected
    1338
    So I look up a device in the Device Center, here is its Reachability Status:
    SNMPv1 Read
    Success
    SNMPv2c Read
    Success
    SNMPv1 Write
    Failed
    SNMPv2c Write
    Failed

  • PCA query not able to fetch data

    HI All, I have installed PCA Business content cube and all the queries available in the Business content relavant to the PCA cube. I have loaded one quarter worth of data. The Profit center - Balance sheet and Profit center - Income statement queries are not able to fetch any data. I am able to execute te query but the report has no data in it.
    Can any one suggest me if there is any thingthat I can do or any ways to dedbug this query.
    Has any one encountered similar poblem

    Are you executing this query "wide open" or you using Characteristic Restrictions and/or Variables that could be filtering out your data? Did you try executing the query using tcode RSRT via 'Execute + Debug'? That may help. Also, take a look at the source InfoProvider in LISTCUBE using the same criteria as the query to see if any data retrieve via that method.

  • Not able to extract performance data from .ETL file using xperf commands. getting error "Events were lost in this trace. Data may be unreliable ..."

    Not able to extract  performance data from .ETL file using xperf commands.
    Xperf Commands:
    xperf –i C:\TempFolder\Test.etl -o C:\TempFolder\BootData.csv  –a process
    Getting following error after executing above command:
    "33288636 Events were lost
    in this trace. 
    Data may be unreliable
    This is usually caused
    by insufficient disk bandwidth for ETW lo
    gging.
    Please try increasing the minimum
    and maximum number of buffers
    and/or
                    the buffer size. 
    Doubling these values would be a good first at
    tempt.
    Please note, though, that
    this action increases the amount of me
    mory
                    reserved
    for ETW buffers, increasing memory pressure on your sce
    nario.
    See "xperf -help start"
    for the associated command line options."
    I changed page size file but its does not work for me.
    Any one have idea, how to solve this problem and extract ETL file data.

    I want to mention one point here. I have total 4 machines out of these 3 machines above
    commands working properly. Only one machine has this problem.<o:p></o:p>
    Hi,
    I consider that you can try to use xperf to collect the trace etl file and see if it can be extracted on this computer:
    Refer to following articles:
    start
    http://msdn.microsoft.com/en-us/library/windows/hardware/hh162977.aspx
    Using Xperf to take a Trace (updated)
    http://blogs.msdn.com/b/pigscanfly/archive/2008/02/16/using-xperf-to-take-a-trace.aspx
    Kate Li
    TechNet Community Support

  • Not able to create new e-mail on N8 using Mail for...

    Not able to create new e-mail on N8 using Mail for Exchange.
    Currently using google for my domain, but settings are the same as explained on the google Sync webpage: http://www.google.com/support/mobile/bin/answer.py?hl=en&answer=147951
    When creating reply on mail the application crashes.  When creating new mail it says "Kan bewerking niet uitvoeren" in english: "Unable to execute action".
    Any idea why creating mail is not possible?
    Regards,
    Joris

    problem is known
    more info there:
    /t5/Nseries-and-S60-Smartphones/N8-syncing-with-Google-contacts-amp-calendar/td-p/772020
    there is little workaround aslo.

  • Why am i not able to see images on some web sites, using safari 5.1.7. I have enabled the tab to display images.

    Does anyone know why I am not able to see images on some web sites using safari 5.1.7?
    I have enabled the apperance tab to display images.

    Safari 5.0.1 or later: Slow or partial webpage loading, or webpage cannot be found

  • Not able to get all the results if i use "get-spdeletedsite" command

    Hi everyone,
    I am not able to get all the results when I use the below powershell command.
    get-spdeletedsite -limit all
    It is giving me only one site, but infact we have more than 100 deleted sites.
    If I use the normal command like below it is giving the below output
    get-spdeletedsite
    Can any one tell me, how can I get all the deleted sites ?
    Best Regards
    Anil Alladi

    Hi  Anil,
    For the Limit parameter of Get-SPDeletedSite cmdlet, when we specify its value to ALL, it  will return all site collections for the given scope.
    For your scenario, the script “Get-SPDeletedSite –Limit ALL” will return all deleted site collections in your SharePoint environment.
    If you want to get all deleted site, you can export the result to csv as below:
    Get-SPDeletedSite | export-csv out.csv -notypeinformation
    Reference:
    http://technet.microsoft.com/en-us/library/hh286316(v=office.15).aspx
    Best Regards,
    Eric
    Eric Tao
    TechNet Community Support

  • Not able to validate the xml document against DTD using SAX

    Hi ,
    i am not able to validate xml document against its DTD using SAX parser even after setting setValidating = true. even if the file is not correct according to DTD , it is not throwing any exception. what could be the reason.? please help..
    kranthi
    this is the code sample i used.
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(true);
         try {
    factory.newSAXParser().parse(new File("sample.xml"), handler);
         } catch (SAXException e) {
         e.printStackTrace();                         System.exit(2);
         } catch (ParserConfigurationException e) {
    e.printStackTrace();
    }

    Hi karthik
    Thanks for your response
    Actually iam a beginner in java coding hence struggling to come up with the things
    I tried putting your code and onserver side i see it is returning 09:12:17,234 INFO [STDOUT] [root: null]
    actually the same program i wrote in java
    and the same method i was calling from the main
    and it is working fine and the xml document is getting displayed one important thing to be noted here is that the factory.newDocumentBuilder().parse(new File(filename));is returing XmlDocument
    and the printing takes place
    but the in same method public static Document parseXMLFile(String filename, boolean b) in servlet
    the line factory.newDocumentBuilder().parse(new File(filename)); is returning DeferredDocumentImpl
    and this creating problem , had it returned XmlDocument
    i would have printed the elements one one
    but as it is returning deferredimpl
    iam unable to print the elements
    could you please tell me why factory.newDocumentBuilder().parse(new File(filename)); is returning DeferredDocumentImpl
    in servlets but in plain java pogram it is returing XmlDocument
    Thanks
    Bhanu

  • I have US$8 cents left in my account.  I have moved to Canada and brought a $50 Canadian prepaid card. I am not able to redeem my C$50 until I use up the US$cents.  However I could not find anything on app store cost 8cents.anyway I can get rid the8cent

    I have US$8 cents left in my account.  I have moved to Canada and brought a $50 Canadian prepaid card. I am not able to redeem my C$50 until I use up the US$cents.  However I could not find anything on app store cost 8cents.anyway I can get rid the 8 cent so that I can top up the $50 canadian prepaid credit

    Click here and request assistance.
    (65561)

  • Hello,  I'm not able to download itunes 10.5 on my dell laptop. It says that an error occured and to download separately and then install.  However, this is stillnot working.  Due to this I am not able to update any applications. I am using windows vista.

    Hello,  I am not able to download itunes 10.5 on my dell laptop.  It says to try to download separately and then install.  However, an error message still comes up.  Due to this, I am not able to update any applications.  I am using windows vista.  If I reinstall itunes entirely, will I loose my many playlists that I have? And will this effect the same playlist that I have on my ipod???

    Installing, and uninstalling, applications never touches or removes the data.
    Clean out and uninstall all the apple programs and software thru Programs and manually.
    Might want to use Revo and CCleaner
    I always use manual standalone installers (and keep a couple backup versions)
    itunes 10.5 may affect iTunes media playlists, not sure, depends on what you have.
    A search of these forums will show some threads.
    I'd clean up vista, you need SP2 or later, and specific error message?
    I wonder as you arenot the first with a dell if maybe the OS or included software.
    Security programs like Norton and older versions of Kaspersky have been implicated.
    Also settings in IE that affect pop-ups and plug-ins.

  • Not able to log in to my account by using Ipod touch?

    Not able to log in to my account by using Ipod Touch?

    Like what happens when you try?
    Just what are you trying to log into?

  • HT1338 not able to access my external hd which i used on my windows pc ntfs3g and mac fuse aren't helping what to do?

    not able to access my external hd which i used on my windows pc ntfs3g and mac fuse aren't helping what to do?

    Bump-I still really need help with this! The connection keeps cutting in and out and I really don't know how to fix it!

Maybe you are looking for

  • "You can't open the application "Flash" because it is not support on the architecture"

    Looking for some help with this. I recently had a system corruption on the MAC machine here in my office. The user was suppose to save his work to the servers which they didn't. The users that was using the Mac ended up losing all there data as the h

  • I can't find where to download captivate 8.

    I have a yearly subscription and recently had to reformat my computer. I've been searching the site for over 30 minutes now and I can't find any link anywhere to download captivate 8. Please help.

  • App Store will not open 10.8.2

    When i try to open the app store or run update i get an error message - "App Store cannot opened because of a problem. Check with the developer to make sure App Store works with this version of OS X" it goes on to say i may have to reinstall app stor

  • Secure Copy and Paste in Sandboxed mode

    Hi, while working on copy-and-paste of mathematical formulae for our ActivMath learning environment, a web-based one, I, of course, chopped to the problem that sandboxes (be them in Java applets, JNLP, JavaScript, Flash, ...) refuse the access to the

  • Can I stop roaming charges incurred while living near an international border?

    I have just moved to northern Maine, near the border of Canada.  The only cell service comes from Canada, from which I will be charged roaming fees.  Is there any way to stop this, since I am not actually across the border?  Thanks.