![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Jul 2005
Location: Athens,Greece
Posts: 39
Rep Power: 0
![]() |
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);
}
}
}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 |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Jul 2005
Location: Athens,Greece
Posts: 39
Rep Power: 0
![]() |
no one? neither one idea?
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|