How to get the whole attachment as a MimeMessage?

I'm finding a way to deal with base64 encoded .eml attachment. I need to parse it to MimeMessage for further process
   for (i=0; i<part.getCount(); i++) {
        currentPart = (MimePart) part.getBodyPart(i);
        if ( file extension is .eml ) {
            InputStream input = currentPart.getInputStream();
            currentPart = new MimeMessage(null, input);
        }with the above code, I would only get the decoded body of the email content, all header information are missing.
From JavaMail API, getInputStream() and writeTo() would only get/write the content part, so I've tried to use:
   for(Enumeration enum = currentPart.getAllHeaderLines(); enum.hasMoreElements();)     {
        currentPart.addHeaderLine((String)enum.nextElement());
   }          I suppose currentPart is a MimeMessage now, but when I try this:
   request.setAttribute("part", (MimeMessage) currentPart.getContent());I would get a ClassCastException
Would anyone give me some suggestion?

I am a little unsure as to what exactly you are trying to achieve, but I will assume you are trying to extract the attachment from one message and parse this attachment as a MimeMessage.
First, the parts in a MimeMessage are grouped in a tree structure so you can't just iterate over the list of parts and expect to get them all, you have to do it recursively.
eg., (pseudo code only)
public void getParts(Part p, List parts) {
  if(p.getContent() != null) {
    if(p.getContent() instanceof Multipart) {
      Multipart mp = (Multipart) content;
      for(int i = 0; i < mp.getCount(); i++) {
        getParts(mp.getBodyPart(i), parts);
    else
       parts.add(p);
// Then call it like:
List parts = new LinkedList();
getParts(part, parts);
// Where "part" is your original messageOnce you have the list of parts, you need to find the attachment. This is done by looking at the "disposition" of the part.
An attachment will usually (although not always) be of type MimeMessage.INLINE or MimeMessage.ATTACHMENT
So... iterate though your parts list looking for attachments
Iterator i = parts.iterator();
Part p = null;
MimeMessage attachment = null;
while(i.hasNext()) {
  p = (Part)i.next();
  // NOTE: p.getDisposition() may be null here
  if(p.getDisposition().equals(MimeMessage.INLINE) || p.getDisposition().equals(MimeMessage.ATTACHMENT)) {
    // You have an attachment
    // Use the data handler to get the stream
    InputStream input= p.getDataHandler().getInputStream();
    // Construct you new MimeMessage
    attachment = new MimeMessage(null, input);
    // Exit the loop
    break;
}The simplest way to test is you have your attachment is to print it's filename with p.getFileName();
You can also bypass creating the part list by adding the disposition check to the first getParts method.

Similar Messages

  • How to get the WHOLE xml document inside a string using XSLT mapping

    Hi folks,
    I have a deep xml structure that I want to embed as body, tags included, in a mail message (not as an attachment).
    I'm trying to use Michal's method in this blog
    /people/michal.krawczyk2/blog/2005/11/01/xi-xml-node-into-a-string-with-graphical-mapping
    However, I can't get it to deliver the entire structure instead of just specific elements.
    Any help is greatly appreciated,
    Thanks,
    Guy

    Ashok,
    I was able to work it out for my case.
    This XSL......
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <inside>
    <namestring>
    <xsl:text disable-output-escaping="yes"><![CDATA[<![CDATA[]]></xsl:text>
    <xsl:copy-of select="outside/name/*"/>
    <xsl:text disable-output-escaping="yes"><![CDATA[]]]]></xsl:text>
    <xsl:text disable-output-escaping="yes"><![CDATA[>]]></xsl:text>
    </namestring>
    </inside>
    </xsl:template>
    </xsl:stylesheet>
    ...will transform this input....
    <?xml version="1.0" encoding="UTF-8"?>
    <outside>
    <name>
    <nameone>name1</nameone>
    <nametwo>name2</nametwo>
    <namethree>name3</namethree>
    </name>
    </outside>
    ...and put the whole lot into the CDATA element.
    Hope this helps you,
    Guy

  • How to get the whole map image after zoom in?

    Hi,
    I use mapviewer API to generate map images and put them in JSP as well as in Java Applet. I called the method getGeneratedImage(). After I using the methods zoomIn() or zoomOut(), I got a new map image. But the size is fixed, so after zoom in I can only see a part of the whole map. I would like to use scrollbar to see other part of the map after zoom in.
    How can I solve this problem? I have the images as predefinied themes saved in database with MBR information.
    Thanks in advance.

    Hi,
    For the map request in MapViewer you may define the data area that you want to display, as well as the device size (width and height). The result is a java Image with width and height sizes. You can draw this image on a canvas with scroll bars, and if the size of the canvas is smaller than the image size, then you should see the scroll bars. But you have to code that. MapViewer will just return an Image with the specified size.
    The zoom in/out options just change the data area, but keeps the device size. Therefore you should use the API methods to set the data area (setBox or setCenterAndSize) and to set the device size (setDeviceSize), in order to control the size of your resulted image, and then draw it on your canvas with scroll bars.
    Regards.

  • How to get the whole list of Iview Templates

    Hi,
    when I navigate:
    Portal Content -> Content Provided by SAP -> Templates -> Iview Templates
    I get a long list of templates including Url Iviews etc
    But, when I try to create my own Iview, the list of potential templates is much smaller, mainly including only the SAP related templates, BSP, Query, ITS etc.
    Does anyone know how to make the full list of Iview Templates available for the Iview creation wizard ?
    Thanks,
    Tomas.

    Hi Tomas,
    which iView templates are offerd within the iView creation wizard is determined by SystemAdmin -- Permissions -- Portal Permissions -- Applications.
    Normally, you will have to have SuperAdminRole to see/change these settings.
    Hope it helps
    Detlev
    PS: Please consider to reward points for helpful answers. Thanks in advance!

  • How to get the whole timestamp from a postgresql database

    Hello,
    Has anyone an idea on how I can get the timestamp from a PostgreSQL database with the fractional seconds information ? I'm using the database connectivity toolkit
    Thanks
    Salim

    and there was even an easier solution
    Why doing simple things when you can struggle for hours

  • How to get the whole payload

    Hey guys,
    I have a requirement where I need to call a stored procedure through a JDBC adapter. The particularity in this call is that I need to send the complete source XML payload as a string in just one element and not mapping each element with input variables of the store procedure.
    I need to know if there is a way to get the incoming XML payload as one big String within XI.
    Any inputs will be helpful !!!
    Cheers,
    Mauricio

    Hi,
    When you write a JAVA Mapping , you need to implement the StreamTransfromationClass which implements execute and setParameter methods.
    In the execute method , you get the Source XML as an InputStream and the need to push the Output XML as the output stream.
    You can use a DOM or SAX parser to prase the XML source and create the target XML.
    To get the entire Source into s String, use this code,
    BufferedReader in = new BufferedReader(new InputStreamReader(inp));
    StringBuffer buffer = new StringBuffer();
    String line="";
    while ((line = in.readLine()) != null) {
    buffer.append(line);
    String sourcexml=buffer.toString();
    Take a look at thise blog for Java Mapping,
    /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i
    Regards,
    Bhavesh

  • After paying for a song, the whole song did NOT download.  How to get the whole song?

    I bought the songs, downloaded them, synced them to my iPod, then clicked play. Two of the new songs stopped playing at around the 50 second mark. So, I played them again to check to make sure I didn't just fast forward... Same thing happened again. I decided to go back onto my computer to redownload it, if the songs just didn't get to download fully, and iTunes didn't let me download it again.
    I have no idea what to do to finally get to listen to the full songs! Can someone help me out?!?

    I decided to go back onto my computer to redownload it, if the songs just didn't get to download fully, and iTunes didn't let me download it again.
    Doublechecking. Did you delete the two songs (and their associated files) from your iTunes library prior to attempting the redownload?

  • When I attach a PDF document in mail only the first page appears. How do I get the whole document to work

    Title says it all. I go to attach file add the fild and the first page shows up in the body of the email. How do I get the whole document to show up?

    You can't get the whole document to appear on your side.
    When you send it, the entire document will be sent.  Normally, clicking on it will open it in preview where you can see all pages.  If you want to see it in this way, just cc: or bcc: yourself on the email when you send it.

  • I want to get the information of the attachment without get the whole body

    POP3 server:
    MimeMultipart mp=(MimeMultipart) message[0].getContent();
    int count=mp.getCount();
    //the server deliver the whole attachment when I use mp.getCount
    Part part=mp.getBodyPart(0);
    //when I use getBodyPart the server deliver the whole body too
    I just want to get the information of the BodyPart,just like filename.
    Some say FetchProfile can do it.But I try it failed.
    How could I do this? Thank you!

    Using POP3, you can't. It's a limitation of the protocol.

  • I recently managed to get the whole casing of my 13" Macbook Pro (Mid-2009) replaced due to a missing foot and dodgy spacebar. The lid is dented and scratched so would like to know how much it would cost to replace? I know its not covered by AppleCare.

    So i took my Macbook Pro 13'' (Mid-2009) into Apple because the spacebar was jammed and I had one of the feet of the bottom casing missing which was unusual (black circles). The unibody and bottom plate had a fair few dents and nicks and under AppleCare I was able to get the whole unibody and bottom case fixed for free. Saved myself a good £181!
    This now leaves my lid which has one or two noticeable dents and the bottom right part is suffering from several scratches. I was wondering how much a new lid would cost if I took it into Apple? I know it won't be covered under AppleCare as its accidental damage but want to know whether its worth paying for to have a once again dent free Macbook Pro .
    As a side note, do Apple upgrade your hardware at all, such as the hard drive or memory? I know it would be cheaper to do it at an independant computer shop or by myself but would like to explore my options first.

    http://www.ifixit.com/
    See my reply to your second question elsewhere.

  • How to get the number of TCS attached to a Defect

    Hi All,
    I have requirement, where in I want to find the number of TCS attaached to one defect.
    For example I will create the Defect in CRMD_ORDER transaction and insert this defect in STWB_2 for some TEST plan againgt the TCS. so here i would insert the same defect for  4 TCS.
    Suggest me wheather this is good practice or not. And  how to get the details of all the TCS attached to a particular Defect.
         Thanks in Advance
    Regards,
    Bharathi.

    Hi All,
    I have requirement, where in I want to find the number of TCS attaached to one defect.
    For example I will create the Defect in CRMD_ORDER transaction and insert this defect in STWB_2 for some TEST plan againgt the TCS. so here i would insert the same defect for  4 TCS.
    Suggest me wheather this is good practice or not. And  how to get the details of all the TCS attached to a particular Defect.
         Thanks in Advance
    Regards,
    Bharathi.

  • How to get the image stored in archieve link as an attachment in work item.

    Hi All,
    through transaction OAWD we are storing scanned images.
    Once this transaction is executed a workitem appears in the inbox of the initiator with the scanned invoice as attachment.
    When the user executes the work item FV60 screen is displayed where the user enters the data based on the scanned invoice attachment.
    After the user Parks the document the custom workflow triggers and a workitem appears in the inbox of an approver.
    Our requirement is that the scanned image should also appear as the attachment.
    Can you please suggest how to get the image stored in archieve link as an attachment in work item.
    Regards
    Shraddha

    Hi Martin,
    with every parked document a scanned image is linked.
    I need to create a link under objects and attachments in the work item, such that when the user clicks that link the image is displayed.
    At present the following functionality is available.
    The BO used is FIPP
    Objects and attachments:
    parkeddocument:AK0108500001252008.(via FIPP binding with WIOBJECT_ID)
    On clicking the link below objects and attachments: the parked document AK0108500001252008 opens in display mode.
    Now we want to have 2 links:
    parkeddocument:AK0108500001252008.
    image.
    When we click on the link image then the scanned invoice linked to the document should get opened.
    I am able to get the image id of the the image through  SAP_WAPI_GET__OBJECTS,
    export parameter leading_object provides the detail.
    But I am not able to figure out how to use it in my workflow to display it as an attachment.
    Hope this will give a better understanding of my question.
    can you please suggest as to how I should proceed with it.

  • How to get the Attachment of a pdf file throug workflow,...

    Hi,
              I have attached pdf the file to the ESS and written the code in webdynrpo. How can I get the file attachment in MSS through Workflow? This attachment should be displayed in the User Decision Activity. Could any one Help me on this issue....?
    Thanks & Regards
    Kannan

    Hi,
      1. From WebDynpro  applicaiton once you create a PDF  in the application you can get back the Xstring of PDF  into the context of the workflow,
    2. Now pass this xstring to workflow container. I assume you might be starting the workflow from Webdynpro application.
    4. Create class method or a BOR and include a method. From that method do the respective coding that is mentioned in the document.
    3. Once you have the PDF  xstring in the workflow container you can attach the PDF  document to user decision step as mentioned in the [document|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/60ff6ad3-729b-2b10-6582-fedc82680a29]
    Regards
    Pavan

  • How to read/get the document attached to PO line item

    Hi experts,
    I got a requirement wherein I need to read/get the document attached at PO line item and to send that document through mail as an attacment .
    please suggest me how to proceed on this.

    actually your are picking up the correct data from Table EKET (EKET-EINDT) but your are printing that in item data loop for EKET might have already executed in your script and the header of that internal table consist the last entry of the table so for that. Fetch the delivery date explicite from the Table EKET when your in item level processing and print that.
    For Example u can use this code.
    To print you have write the this code in Script item level printing window "MAIN" window
    Following perform is called to get the line item delivery date in PO
    {/: PERFORM GET_DEL_DATE IN PROGRAM ZPerform_prog
    /: USING &EKPO-EBELN&
    /: USING &EKPO-EBELP&
    /: CHANGING &DEL_DATE&
    /: ENDPERFORM}
    {* Dellivery date &DEL_DATE& }
    write the below code in the Z program "ZPerform_prog"
    { FORM get_del_date  TABLES in_par STRUCTURE itcsy
                             out_par STRUCTURE itcsy.
      READ TABLE in_par WITH KEY 'EKPO-EBELN'.
      CHECK sy-subrc = 0.
      $_po_no = in_par-value.
      READ TABLE in_par WITH KEY 'EKPO-EBELP'.
      CHECK sy-subrc = 0.
      $_po_line = in_par-value.
      SELECT *
      FROM eket UP TO 1 ROWS WHERE ebeln EQ $_po_no AND ebelp EQ $_po_line.
        $_del_date = eket-eindt.
        CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
          EXPORTING
            date_internal            = eket-eindt
          IMPORTING
            date_external            = $_del_date
          EXCEPTIONS
            date_internal_is_invalid = 1
            OTHERS                   = 2.
        READ TABLE out_par WITH KEY 'DEL_DATE'.
        CHECK sy-subrc EQ 0.
        out_par-value = $_del_date.
        MODIFY out_par
                    INDEX sy-tabix.
        CLEAR : $_po_no , $_po_line ,$_del_date.
      ENDSELECT.
    ENDFORM.                    "GET_DEL_DATE }

  • Recently downloaded a whole cd on itunes. However, as it was downloading one of the songs was interrupted and didn't fully download. How do i get the whole song without having to pay again?

    I recently downloaded a whole cd on itunes. However, as it was downloading one of the songs was interrupted and didn't fully download. How do i get the whole song without having to pay again?

    Depending upon what country that you are in (music can't be re-downloaded in all countries) then try deleting the incomplete track from your iTunes library and redownload it via the Purchased link under Quick Links on the right-hand side of the iTunes store home page on your computer's iTunes.
    If you aren't in a country where you can re-download music then you will need to contact iTunes Support - try the 'report a problem' link from your purchase history : log into your account on your computer's iTunes via the Store > View Account menu option and you should then see a Purchase History section with a 'see all' link to the right of it ; click on that and you should see a list of your purchases ; find that song and use the 'Report a Problem' link and fill in details about the problem (iTunes support should reply within, I think, about 24 hours).
    If the 'report a problem' link doesn't work (it's been taking some people to this site on a browser instead of showing a form in iTunes) then you can try contacting iTunes support via this page : http://www.apple.com/support/itunes/contact/- click on Contact iTunes Store Support on the right-hand side of the page.

Maybe you are looking for

  • Help with image clipping with FCP 7 video filters

    Hi there,      I'm working with an image with text (one jpeg, the other psd), and when I apply a video filter (glow, bloom, or the like) that extends the outside of the image, it clips the edges.      I've tried expanding the area around the image in

  • Which Phone Should I Buy

    I am intending to buy a new Firefox OS phone eventually. My only question is if I should wait until the OS software is more mature. I know there's currently two Firefox OS phones available in the US (Flame and ZTE Open C).

  • SAP Search help in Adobe forms

    Hi , Can any one help out by mentioning the steps to capture details using webdynpro with search help and then switching on to pdf application with those details? Regards, Deepthi Lakshmi.A.

  • Installing QuickTime Standalone error  aaargh!

    I just got a Ipod Nano, but I can't use it because I can't get ITunes to work. I've been reading up on this board for a couple of hours and trying the suggestions but I haven't gotten anything to work. Basically at the beginning I got teh -3 error al

  • My Macbook Displats buzzes big time!! Help!!

    Hello People, My Macbook arrived on Friday and everything seemed great (apart from the Mooing). But yesterday when I faded the screen up from dimmed the screen made a very unpleasant loud buzzing sound which stops when the screen is at maximum output