Hi Danny,
Thanks a ton for the help. I was successful to delete the attachment. Here's
how I did it:
----------------------------------------------------------------------------
try{
System.out.println("***Attachment deletion block started ***");
MimeMessage message = mail.getMessage();
MimeMultipart mmp = (MimeMultipart)message.getContent();
for (int i=0; i<mmp.getCount(); i++){
MimeBodyPart mbp=(MimeBodyPart)mmp.getBodyPart(i);
System.out.println("body part " + mmp.getBodyPart(i));
if(hasToBeRemoved(mbp)) {
System.out.println("attachment name matches 'credentials.txt'" +
+would be removed");
mmp.removeBodyPart(i);
i--;
}
}
message.setContent(mmp);
message.saveChanges();
}catch(IOException ioe) {
System.out.println("Exception caught while creating a new " +
"instance of MimeMultipart" + ioe);
}
System.out.println("***Attachment deletion block ended ***");
.
.
.
public boolean hasToBeRemoved(MimeBodyPart mbp){
try{
String disposition = mbp.getDisposition();
if ((disposition !=null) && (disposition.equals(Part.ATTACHMENT))){
if (mbp.getFileName().equalsIgnoreCase("credentials.txt")){
System.out.println(mbp.getFileName());
System.out.println("Credentials file will be removed");
return true;
}
}
}catch (Exception ex){
System.out.println("Ex caught ");
}
----------------------------------------------------------------------------
The hasToBeRemoved() method checks for the file name with the help of
getFileName() and compares it with the string I supplied. hasToBeRemoved()
method returns true if comparison is succeeds.
Thnkx,
Gaurav Handa
cell +91-9868867223
-----Original Message-----
From: Danny Angus [mailto:[EMAIL PROTECTED]
Sent: Monday, September 26, 2005 1:58 PM
To: James Users List
Subject: Re: Can attachment be removed after intercepting on mail server?
> on the apache James mail server I am having, I need to remove a
particular
> attachment from the mail after I receive it on the server.
> I was successful
> to intercept the attachment and read data from it. But the other part of
> problem is that I have to write data in the same file or simply remove
the
> file from mail.
Gaurav,
I really think you need to study JavaMail to answer these questions.
Try creating a new MimeMultipart and copying only those parts you want to
retain to the new multipart from the old one.
Then set the new one as the content of the message and save changes.
Or just modify the attachement and save changes.
d.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]