How to save inline images and attachments separatley?

Hi,
I want to save all inline images into a certain directory and all attachments into another directory.
I use the following code to do this:
  Multipart multipart = (Multipart) message.getContent();
        for (int x = 0; x < multipart.getCount(); x++) {
            BodyPart bodyPart = multipart.getBodyPart(x);
            String disposition = bodyPart.getDisposition();
            if(disposition != null){
                 log.debug("Disposition: " + disposition);
                 if (disposition.equals(BodyPart.ATTACHMENT)) {
                      log.debug("Mail has attachment: ");
                     DataHandler handler = bodyPart.getDataHandler();
                     log.debug("FILENAME: " + handler.getName());                    
                     saveAttachment(session, bodyPart, emailData);
                 else if(disposition.equals(BodyPart.INLINE)){
                      log.debug("Mail has inline attachment: ");
                     DataHandler handler = bodyPart.getDataHandler();
                     log.debug("Inline FILENAME: " + handler.getName());
                     saveInlineAttachment(session, bodyPart, emailData);
            else {
                 log.debug(bodyPart.getContent());
        }This approach works when the email has inline images only or attachments only.
It does not work when the email has both inline images and attachments. (Only the attachments are saved).
Come someone please help me correct my solution so that it can process an email that has both inline images and attachments and save them in different directories.
Thank you

Thanks bshannon.
It took me a while to understand what you meant but I think I finally got it.
I modified the getText method in order to save the embedded images:
private Image getImages(Part p, EmailData emailData, String ext) throws MessagingException, IOException {
         if (p.isMimeType("image/*")) {
            InputStream is = p.getInputStream();         
            BufferedImage im = ImageIO.read(is);
            String fileName = "attachments/inline/body " + inlineImageNumber++ + "." + ext;
            File imageFile = new File(fileName);
            ImageIO.write(im,ext,imageFile);
            is.close();
            emailData.getInlineAttachments().add(fileName);
            return null;
        if (p.isMimeType("multipart/related")) {
            Multipart mp = (Multipart)p.getContent();
            Image image = null;
            for (int i = 0; i < mp.getCount(); i++) {
                Part bp = mp.getBodyPart(i);
                if (bp.isMimeType("image/jpeg")) {
                    if (image == null){
                        image = getImages(bp, emailData, "jpg");
                    continue;
                else if (bp.isMimeType("image/gif")) {
                    if (image == null){
                        image = getImages(bp, emailData, "gif");
                    continue;
                else if (bp.isMimeType("image/bmp")) {
                    if (image == null){
                        image = getImages(bp, emailData, "bmp");
                    continue;
                else if (bp.isMimeType("image/png")) {
                    if (image == null){
                        image = getImages(bp, emailData, "png");
                    continue;
            return image;
        else if (p.isMimeType("multipart/*")) {
            Multipart mp = (Multipart)p.getContent();
            for (int i = 0; i < mp.getCount(); i++) {
                Image image = getImages(mp.getBodyPart(i), emailData, "");
                if (image != null){
                    return image;
        return null;
    }

Similar Messages

  • How to save inline images

    Hi,
    Using java mail api.
    Not able to save those images which are embedded as part of a mail message body.
    It has no filename.
    How can it be stored and showed as part of web-application whichreplicates the microsoft outlook.

    Thank you for your reply.
    But I hav few questions here.
    How do I translate cid references and save?
    I get cid reference name with getHeader("Content-ID");
    But this gives me String.Just a name.
    How do I save this?
    ***Is this the way it is or any othe way is there.***
    Plz Plz PLz help me.
    Its a very big big issue for me.
    It would be helpful If anybody can help witha bit of coding example.

  • How to Save an image and retreve the same image with edit option!! ???

    I am facing with a problem
    I have a image which is preloaded, user accessing the image should be provided with a option of adding a text on some part of image etc and save it. Later when that imagine is tried and retrived it should display the edited and saved image and allow user to edit again.The text will be written in a square box which can be dragged anywhere on the image. Is java script and ajax best for this.?
    Can anyone help in showing the basic things i need to follow to achieve this.
    Thanks in Advance
    Edited by: aadi on Feb 12, 2008 9:41 PM

    You could try to write a web service that returns a byte array and convert the image to bytes, and convert it back into an image again.

  • How to save appropriate images and then discard the saved images after using.

    Hi,
    The attached program is used for gesture recognition and playing the corresponding audio file for each recognized pattern. It is saving all the images that are captured and is using in pattern matching. if pattern for "A" is captured ,then almost 10 to 15 intermediate images are captured along with pattern "A". If all are pattern matched then audio file of "A" will be played for 4 or 5 times which is not desirable. Also the images saved in the imaq write folder are getting piled up. They should be discarded after they are used up in pattern matching otherwise it would be a waste of system memory. Can anybody  advice in correcting.
    Thanking you. 
    Attachments:
    program help.zip ‏721 KB

    Hi,
    The attached program is used for gesture recognition and playing the corresponding audio file for each recognized pattern. It is saving all the images that are captured and is using in pattern matching. if pattern for "A" is captured ,then almost 10 to 15 intermediate images are captured along with pattern "A". If all are pattern matched then audio file of "A" will be played for 4 or 5 times which is not desirable. Also the images saved in the imaq write folder are getting piled up. They should be discarded after they are used up in pattern matching otherwise it would be a waste of system memory. Can anybody  advice in correcting.
    Thanking you. 
    Attachments:
    program help.zip ‏721 KB

  • How to save an image to database and retreive from it.

    how to save an image retreived from an bytearray to database and retreive back the image from database....pls specify the steps and the query.

    You can use the JDBC API for database connectivity and you can use SQL to query the database.
    JDBC tutorial: http://www.google.com/search?q=jdbc+tutorial+site:sun.com
    SQL tutorial: http://www.google.com/search?q=sql+tutorial+site:w3schools.com

  • How can I save the images and movies on a  external Disk from iphoto program, to protect the images when problems occur in the laptop,

    How can I save the images and movies on a  external Disk from iphoto program, to protect the images when problems occur in the laptop,

    Most Simple Back Up:
    Drag the iPhoto Library from your Pictures Folder to another Disk. This will make a copy on that disk.
    Slightly more complex: Use an app that will do incremental back ups. This is a very good way to work. The first time you run the back up the app will make a complete copy of the Library. Thereafter it will update the back up with the changes you have made. That makes subsequent back ups much faster. Many of these apps also have scheduling capabilities: So set it up and it will do the back up automatically.
    Example of such apps: Chronosync - but there are many others. Search on MacUpdate or the App Store
    If you want to back up the Photos only:
    Export them using the File -> Export command.
    This User Tip
    https://discussions.apple.com/docs/DOC-4921
    has details of the options in the Export dialogue.

  • How to save the image in the form?

    As thread, how to save the image into a file from the pdf form - image box?
    I have Adobe Acrobat 9 Pro extended.

    Hi Sandy,
    Sorry for Delay.Could you please provide script code for the Button and in which event we want to add the code
    I want to Save the lot of images in the PDF. For that I kept Image field in the form.Here I am able to upload the images but those are not saved.
    If possible please share the details document.
    Please help me.
    Thanks,
    Ravi.

  • How to save an image as a PICT resource file?

    Can someone tell me how to save an image as a PICT resource file? I'd like to make ikons in Photoshop and save them in this format, but I 'm not finding any leads. Thanks!

    If you have Resorcerer from "ancient times" it of course can handle resource forks since that's was it's goal in life.
    There are lots of icon creation apps these days.  Do a search for "icon" on macupdate.com to see what's available.  For example that search finds:
    iconXprit
    Icon Builder X

  • How to save an image as PDF?

    Hi,
    I need help o how to save an Image as PDF file?? is this possible?

    Under Getting Started in the welcome window click Create PDF
    Open your image
    File>Save As...PDF
    But I am finding that there are limitations on how big the image can be. I am trying to save a 20mb jpeg to pdf in acrobat and having issues. Good luck!

  • How to upload the image and diplay the image in the browser using jsp

    How to upload the image and diplay the image in the browser using jsp
    thanks
    shan

    i'll suggest looking for sample code or tutorial with a relevant query in google, which as far more time than us to answer this type of reccurent question

  • How to save my emails and adressbook files from an old ibook?

    How to save my emails and adressbook files from an old ibook (bought around 2002) ?
    The screen from the old ibook doesn´t work anymore (logicboard problem I guess).
    I saved everything else with starting it in target modus. That worked fine.
    I want to delete the files after that as well, because I wanna give away the old ibook and don´t want anyone to read my emails!
    Little helpers I have:
    A running MacBook
    External Screen (and cables to connect)
    Fire Wire Cable

    Don't know how helpful this will be but I often copy mail from one computer to another, I drag the mail from the mail window to the other computers drop box, then from the other computer double click it and mail asks me what I want to do with it, of course without a screen you'd need to use back to my mac.
    If you don't have back to my mac running, you could set up a second user account on the newer mac, import everything via target mode as suggested by c above, and then drag the mail to the first user account drop box.

  • How to import a image and compare with another image to find their deviation

    i am new to labview , can anyone tell how to import a image and compare  it with another image  to find their deviation
    Solved!
    Go to Solution.

    This is an quite easy task using the Vision Development Module.
    There you can acquire images from cameras or read them form the harddrive, then differntiate them or since VDM 2010 calculate the optical flow between consecutive images.
    Christian

  • How to store photo images and thumbimpressions in oracle 10g database

    Hi all
    I have an web application running in Oracle 10g rel 1 database server in RHEL3. It has application server with forms and j2ee component as middle tier. I need to store centrally photo images and thumb impressions and use it in our application without any overhead on retrieval and performance of web application. what will be optimized method of storage of photo and thumb impressions. Awaiting your valuable suggestions.
    Regards
    Vijay Kumar

    Hi Vijay,
    How to store photo images and thumbimpressions in oracle 10g database I have working code here for storing photos in Oracle tables that you may find useful:
    http://www.dba-oracle.com/t_storing_insert_photo_pictures_tables.htm
    Hope this helps . . .
    Donald K. Burleson
    Oracle Press author
    Author of "Oracle Tuning: The Definitive Reference"
    http://www.rampant-books.com/book_2005_1_awr_proactive_tuning.htm

  • How to save a game  and then load

    My final project of BSCS (Bachelor of Science in Computer Science) is a Multiplayer online Board game...Distributed Ludo...
    This project is in its final steps and I�m facing some difficulties.
    I do not know how to save the game and load it again. Can anybody guide me to the process?

    Saving a game is just persisting the data required for the game.
    Loading a game means reading the saved data and setting the attributes of the game (and player and ...) to start exactly the point where it was saved.
    So the steps to save are
    1. Identify the data necessary for retaining the same state when needed.
    2. Decide the data file format and structure.
    3. Get the snapshot of necessary attributes
    4. Save the data using APIs
    Steps to load are
    1. Read the data using APIs.
    2. Set the game attributes.
    3. Update the model and view accordingly.
    Hope this helps.

  • How do I embed images and hyperlinks to my mail signature

    how do I embed images and hyperlinks to my mail signature?

    How to Make an HTML Signature in Apple Mail

Maybe you are looking for

  • Error in schema validation in XI. Please help!

    Hi Experts,    I have a FILE to proxy scenario. In the sender agreement I have selected schema validation by Adapter. (Other option is by Integration Engine). Now when the file I get an error in sender file communication channel monitoring: Error: co

  • Deadline seems to be dead for me!!!

    I have done this before ... now i am wondering whats wrong here.. i have an idea what it could be... but just wanted to run it thru the ppl here just to check if i am missing something... I added a deadline to a display workitem.. 1minute starting fr

  • PLEASE ANSWER: Master Collection 5, Platform Windows & Mac?

    Just purchased a Master Collection Creative Suite 5 and the packaging stated: System Requirements: Windows and Mac. I haven't opened the package yet and can't find the Mac logo any where on the packaging. Is this a new development by Adobe that the s

  • Issues deactivating my CS5 Suit while trying to uninstall it

    I need to format my macbook, so I'm having issues deactivating my CS5 Suit while trying to uninstall it, to reinstall it after the format has been completed. Anyone know whats going on?

  • MacBook not receiving .mac emails

    I have set up the mail programme to receive my .mac account emails as I have done with other laptop and desktop devices in the past - but for some reason emails are not coming through to it. I have the right incoming and outgoing servers set. Can any