Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 15th, 2005, 10:48 AM   #1
tsofras
Programmer
 
tsofras's Avatar
 
Join Date: Jul 2005
Location: Athens,Greece
Posts: 39
Rep Power: 0 tsofras is an unknown quantity at this point
Question Java mail problem with attachment

Hello there, i am making a small project using java mail, and i have a problem just to print if there is an attachment in the mail. It might be that the "Content-Disposition" is not availiable in this mail server, so all the parts has the "disposition = null" .
I will provide my code below:
package IMAIL;


import  javax.mail.*;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.swing.*;
import  java.util.*;
import java.io.*;




public class GetPic {
     public static void main(String args[])
      {

            
            String host="smtp.myhost";
            String username="myusername";
            String password="mypassword";


            Properties props = new Properties();
           
           Session session = Session.getDefaultInstance(props);

          try {
           
            Store store = session.getStore("imap");
            store.connect(host,username,password);

            // Get folder
            Folder folder = store.getFolder("Inbox");
            folder.open(Folder.READ_ONLY);
            // Get directory
            Message message[] = folder.getMessages();
            
              for (int i=0, n=message.length; i<n; i++) {
                // Check out if it mime Message
                //if ((message[i].getSubject().equals("imailtesting"))) {
                    System.out.println(i + ": " + message[i].getFrom()[0]
                    + "\t" + message[i].getSubject());
                    //Now get attachment (multiparts)
                  
                  Multipart mp = (Multipart) message[i].getContent();
                  int numberOfnodyparts = mp.getCount();
                  System.out.println("numberofnodyparts:"+numberOfnodyparts);
                  //Count multipart occurences
                    for (int j=0; j<numberOfnodyparts; j++)
                    {

                      Part part = mp.getBodyPart(j);

                      System.out.println("Bodypart:"+part);
                      //
                      String disposition = part.getDisposition();
                      System.out.println("disposition:"+disposition);
                      //if it's attachment save it
                      if ((disposition != null) &&
                         ((disposition.equals(part.ATTACHMENT) || (disposition.equals(Part.INLINE)))))
                      {
                          System.out.println("FileName:"+part.getFileName());

                          //Print atatchment type
                         System.out.println("Attachment type::" + part.getContentType());
                          System.out.println("Content-Type::\""+part.getContentType()+"END");
                         
                      }
                      
                    }

            }
            folder.close(false);
            store.close();
            System.exit(0);

        }
        catch (Exception e)
        {
            System.out.println("oops something went wrong!::"+e);

        }
    }
    
    }
These are the results:
C:\j2sdk1.4.2_10\bin\java -Didea.launcher.port=7534 "-Didea.launcher.bin.path=C:\Program Files\JetBrains\IntelliJ IDEA 5.0\bin" -Dfile.encoding=windows-1253 -classpath "C:\j2sdk1.4.2_10\jre\lib\charsets.jar;C:\j2sdk1.4.2_10\jre\lib\jce.jar;C:\j2sdk1.4.2_10\jre\lib\jsse.jar;C:\j2sdk1.4.2_10\jre\lib\plugin.jar;C:\j2sdk1.4.2_10\jre\lib\rt.jar;C:\j2sdk1.4.2_10\jre\lib\sunrsasign.jar;C:\j2sdk1.4.2_10\jre\lib\ext\dnsns.jar;C:\j2sdk1.4.2_10\jre\lib\ext\ldapsec.jar;C:\j2sdk1.4.2_10\jre\lib\ext\localedata.jar;C:\j2sdk1.4.2_10\jre\lib\ext\sunjce_provider.jar;C:\Projects\GetPicFromIMAIL\classes;C:\j2sdk1.4.2_10\javamail-1.3.3_01\mail.jar;C:\tomcat 4.1.31\common\lib\activation.jar;C:\Program Files\JetBrains\IntelliJ IDEA 5.0\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain IMAIL.GetPic
0: 6973665773@imode.gr	τεςτ
numberofnodyparts:2
Bodypart:com.sun.mail.imap.IMAPBodyPart@115273a
disposition:null
Bodypart:com.sun.mail.imap.IMAPBodyPart@1d80e6d
disposition:null
1: 6973665773@imode.gr	καδμ
numberofnodyparts:2
Bodypart:com.sun.mail.imap.IMAPBodyPart@19b5393
disposition:null
Bodypart:com.sun.mail.imap.IMAPBodyPart@8bdcd2
disposition:null

Process finished with exit code 0

I have searched a lot in Java forums, java docs, java mail docs and a lot of other stuff but my brain is going to explode for today

I know that maybe i have to check the "Body" of the mail, or maybe i have to change the encoding...

So if anyone has an idea plz tell me
Thx in advance
tsofras is offline   Reply With Quote
Old Dec 16th, 2005, 4:45 AM   #2
tsofras
Programmer
 
tsofras's Avatar
 
Join Date: Jul 2005
Location: Athens,Greece
Posts: 39
Rep Power: 0 tsofras is an unknown quantity at this point
no one? neither one idea?
tsofras is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:13 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC