How to remove some header information (boundary ; ------=_Part_0_8670.1009527247068--) !_NEWLINE_!at the end of the file sended via JAVAMAIL API.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Friday, December 28, 2001 02:07 AM

Hi, I have some problem using JavaMail API 1.2. When I send a file using the following code (Send) and I retrieve the file using the code (Get) the file size at the end, is not the same. this difference is coming from some header information added at the end of the file. Depending of the setHeader I use, I have this : ------------------------START------------------- VERSION INFORMATION: TNS for 32-bit Windows: Version 8.0.6.0.0 - Production Oracle Bequeath NT Protocol Adapter for 32-bit Windows: Version 8.0.6.0.0 - Production Time: 11-OCT-01 08:12:35 Tracing not turned on. ÿÿÿÿ=ªíÿOõ×ovÿ]4÷»×Ž6ÓOÿ ------------------------EN   More>>

Hi,

I have some problem using JavaMail API 1.2. When I send a file using the following code (Send)
and I retrieve the file using the code (Get) the file size at the end, is not the same.
this difference is coming from some header information added at the end of the file.


Depending of the setHeader I use, I have this :


------------------------START-------------------
VERSION INFORMATION:
TNS for 32-bit Windows: Version 8.0.6.0.0 - Production
Oracle Bequeath NT Protocol Adapter for 32-bit Windows: Version 8.0.6.0.0 - Production
Time: 11-OCT-01 08:12:35
Tracing not turned on.


ÿÿÿÿ=ªíÿOõ×ovÿ]4÷»×Ž6ÓOÿ

------------------------END----------------------


Or with another setHeader


------------------------START-------------------
VERSION INFORMATION:
TNS for 32-bit Windows: Version 8.0.6.0.0 - Production
Oracle Bequeath NT Protocol Adapter for 32-bit Windows: Version 8.0.6.0.0 - Production
Time: 11-OCT-01 08:12:35
Tracing not turned on.



------=_Part_0_8670.1009527247068--

------------------------END----------------------


Without setHeader, I have the same problem.


Why I have this : (------=_Part_0_8670.1009527247068--) or the binary format(ÿÿÿÿ=ªíÿOõ×ovÿ]4÷»×Ž6ÓOÿ ) ?


Here for example I have use TEXT, but it's the same problem for BINARY file.


Could you help me, I have missed some think ! what ?


Here are the SEND and GET code

>

			
				


----------------------Send CODE --------------------

public static void main(java.lang.String[] args) throws MessagingException {
// Insert code to start the application here.
if (args.length < 4) {
System.out.println(
"Usage: java SendMail " + "protocol smtpHost fromAddress toAddress filename");
System.exit(1);
}

String smtpHost = args[0];
String fromAddress = args[1];
String toAddress = args[2];
String filename = args[3];

Properties properties = System.getProperties();
properties.put("mail.smtp.host", smtpHost);
Session session = Session.getInstance(properties, null);

//MimeMessage message = new MimeMessage(session);
Message message = new MimeMessage(session);

message.setFrom(new InternetAddress(fromAddress));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(toAddress));

message.setSubject("Test avec attachment");
message.setHeader("Content-Type","multipart/mixed");

//message.setText("Message Send via JAVAMAIL");

// Create the first Part of the Message
//MimeBodyPart messageBodyPart1 = new MimeBodyPart();
BodyPart messageBodyPart1 = new MimeBodyPart();

// Fill the message
messageBodyPart1.setText("Message Send via JAVAMAIL with attachment");

messageBodyPart1.setHeader("Content-Type","text/plain");

// Create second body part of the message
//MimeBodyPart messageBodyPart2 = new MimeBodyPart();

BodyPart messageBodyPart2 = new MimeBodyPart();

// Get the attachment

File file = new File(filename);


if (file.exists()) {
System.out.println("file : " + filename);

// Attach the filename to the name

// Set the data handler to the attachment

//DataSource source = new FileDataSource(file);
FileDataSource source = new FileDataSource(filename);

messageBodyPart2.setDataHandler(new DataHandler(source));
messageBodyPart2.setDisposition(Part.ATTACHMENT);
messageBodyPart2.setFileName(filename);
messageBodyPart2.setHeader("Content-Transfer-Encoding", "Base64");

//messageBodyPart2.setHeader("Content-Type", "application/octet-stream");
//messageBodyPart2.setHeader("Content-Type","text/plain");
//messageBodyPart2.addHeader("Content-Transfer-Encoding", "Base64");


System.out.println("Message Send");
} else {

System.out.println("File not found");

messageBodyPart2.setText("Message without attach, File not found");


}


// Create a Multipart
//Multipart multipart = new MimeMultipart();
Multipart multipart = new MimeMultipart();

// Add part one

multipart.addBodyPart(messageBodyPart1);

// Part two is attachment
multipart.addBodyPart(messageBodyPart2);
message.setContent(multipart);

message.saveChanges();

Transport.send(message);

System.out.println("End");
}
---------------------End send Code ---------------------


--------------------Get Code-------------------------
// Insert code to start the application here.
if (args.length < 4) {
System.out.println(
"Usage: java GetMail " + "host username password messageNumber");
System.exit(1);
}

String host = args[0];
String username = args[1];
String password = args[2];
int messageNumber = Integer.parseInt(args[3]);
int j;


Session session = Session.getInstance(System.getProperties(), null);
// Use for test purpose
//session.setDebug(true);

// Use for test purpose

URLName urln = new URLName("imap://yUser:myPassword@myServerMail/");
Store store = session.getStore(urln);
store.connect();

Folder inbox = store.getDefaultFolder().getFolder("INBOX");
//inbox.open(Folder.READ_ONLY);
inbox.open(Folder.READ_WRITE);

System.out.println(" Number of message in INBOX :" + inbox.getMessageCount());

if (inbox.getMessageCount() > 0) {

Message message = inbox.getMessage(inbox.getMessageCount());
message.setFlags(new Flags(Flags.Flag.SEEN), true);
System.out.println("SUBJECT IS: " + message.getSubject());

System.out.println("CONTENT TYPE IS " + message.getContentType());


if (message.isMimeType("multipart/*")) {
Multipart multipart = (Multipart) message.getContent();

System.out.println("Nbre " + multipart.getCount());

BodyPart firstPart = new MimeBodyPart();

firstPart = multipart.getBodyPart(0);
System.out.println("firstPart Content TYPE 0 is " + firstPart.getContentType());
System.out.println("firstPart 0 is " + firstPart.getContent());
System.out.println("contentType 2 " + firstPart.getContentType());

if (firstPart.isMimeType("TEXT/*")) {
j = 1;
System.out.println("J=1, TEXT/* ");
} else {
j = 0;
System.out.println("J=0, No Text ");
}

for (int i = j; i < multipart.getCount(); i++) {

firstPart = multipart.getBodyPart(i);

if (!firstPart.isMimeType("TEXT/*")) {

DataHandler dh = firstPart.getDataHandler();
OutputStream os = new FileOutputStream(firstPart.getFileName()+"M");
dh.writeTo(os);
os.close();
System.out.println("copie No " + i);

} else
System.out.println("Multipart " + i + " is " + firstPart.getContent());
}

if (firstPart.isMimeType("text/*")) {
System.out.println("first page is " + firstPart.getContent());
} else {
System.out.println("bis " + message.getContentType());
}

}



message.setFlags(new Flags(Flags.Flag.DELETED), true);
System.out.println("message set Delete");


}
else {
System.out.println("Invalid message number.");
}

inbox.close(true);
store.close();
------------------------End Get Code --------------------

   <<Less

Re: How to remove some header information (boundary ; ------=_Part_0_8670.1009527247068--) !_NEWLINE_!at the end of the file sended via JAVAMAIL API.

Posted By:   Anonymous  
Posted On:   Tuesday, January 15, 2002 11:42 PM

For your information, problem seems to come from our Mail Server.
About | Sitemap | Contact