1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| public void dumpPart(Message message) throws Exception {
String TextBody="";
path=null;
bodytxt="vide";
bodyhtml= "vide";
System.out.println("Start Body");
//cas d'un message
//cas d'un mimeMessage
if (message instanceof MimeMessage) {
System.out.println("Massegae 1" + message.toString());
MimeMessage mime = ((MimeMessage) message);
System.out.println("Massegae 1" + mime.getContent());
if (mime.getContent() instanceof MimeMultipart) {
MimeMultipart content = (MimeMultipart) mime.getContent();
MimeBodyPart body;
System.out.println("Massegae 2" + content.toString());
for (int i = 0; i < content.getCount(); i++) {
if (content.getBodyPart(i) instanceof MimeBodyPart) {
body = (MimeBodyPart) content.getBodyPart(i);
System.out.println("Massegae 3" + body.getContentType());
if (body.getContentType().equals("text/plain")) {
TextBody+=(String) message.getContent();
System.out.println("Massegae 4" + TextBody);
bodytxt = TextBody ;
} else if (body.getContentType().equals("text/html")) {
String ss;
// Log.i("msg",(String) message.getContent());
BufferedReader in = new BufferedReader(new InputStreamReader(body.getInputStream()));
while ((ss = in.readLine()) != null) {
TextBody += ss + "\n";
}
bodyhtml = TextBody;
System.out.println("Massegae 5" + TextBody);
} else {
System.out.println("Massegae 6:attttt" );
String disp = body.getDisposition();
if (disp != null && disp.equalsIgnoreCase(body.ATTACHMENT)) {
File f=new File("/sdcard/andsync/"+compte.getAddmail());
f.mkdirs();
InputStream is = body.getInputStream();
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File("/sdcard/andsync/"+compte.getAddmail()+"/"+body.getFileName())));
byte[] buff = new byte[2048];
int ret = 0, count = 0;
while ((ret = is.read(buff)) > 0) {
bos.write(buff, 0, ret);
count += ret;
}
bos.close();
is.close();
path =path + "/sdcard/andsync/"+compte.getAddmail()+"/"+body.getFileName();
System.out.println("Massegae 7" + "Fin de creation");
} else {
String s;
BufferedReader in = new BufferedReader(new InputStreamReader(body.getInputStream()));
while ((s = in.readLine()) != null) {
TextBody += s + "\n";
}
System.out.println("Massegae 8" + TextBody);
//Log.i("msg",TextBody);
bodyhtml = TextBody;
in.close();
}
}
}
}
}
}
String ct = message.getContentType();
if (message.isMimeType("text/plain")) {
TextBody +=(String)message.getContent();
System.out.println("Massegae 9" + TextBody);
bodytxt=TextBody;
} else {
}
System.out.println("END Body");
} |
Partager