determine the icon for mime attachments in lotus domino - java

I am using the Java-API for Lotus Domino. Current version of Domino is 8.5. I connect to Domino over DIIOP/CORBA. I want to create a document (email) with attachments. The email is a multipart MIME document. Attaching a file ist quite easy and works perfectly. However the attachment gets a generic document icon (empty gray page). I would like to set an appropriate icon for the actual content type - e.g. a word-icon for a .doc-file. Is this possible in any way? I have tried to modify the content type parameter of the setContentFromBytes-method but to no avail.
here's a sample code:
session.setConvertMIME(false);
File file = new File("c:\\temp\\file.docx");
MIMEEntity child = document.createChildEntity();
MIMEHeader header = child.createHeader("Content-Disposition");
header.setHeaderVal("attachment; filename=" + file.getName());
header = child.createHeader("Content-ID");
header.setHeaderVal(file.getName());
Stream stream = session.createStream();
stream.open(file.getAbsolutePath(), "binary");
child.setContentFromBytes(stream,"application/vnd.openxmlformats-officedocument.wordprocessingml.document", MIMEEntity.ENC_IDENTITY_BINARY);
child.encodeContent(MIMEEntity.ENC_BASE64);
stream.close();
stream.truncate();
// other code here...
session.setConvertMIME(true);
I have also tried the older "application/msword" content type but it also dont work.
Any ideas how to set the icon for the attachment?
Thanks!

I don't think it is possible.
I believe the icon is looked up (from the registry) on the system that executes the code that attaches the file. Since you are using DIIOP/CORBA, that lookup occurs on the server. It's unlikely that the server has the Office software installed so it can't find the icon and just uses the generic one.

Related

Unable to fetch HTML content from mail in Lotus Notes, getMIMEEntity() returns a null even after setConvertMIME(false)

I am trying to read the HTML contents of a Document object(mail) as a part of my plug in development in Lotus Notes 9.
With this HTML content, we would like to create a file and send it as an attachment file in our query, so we can preserve the formatting, images, etc.
Even after session.setConvertMIME(false); I still do not get the Mime entity when I call doc.getMIMEEntity().
I have made preferences setting in Preferences>Mail>Internet
Internet mail format to "HTML and plain text".
I have tried doc.createMIMEEntity and then tried to retrieve it
mimePart = doc.getMIMEEntity("Body");
When i right clicked on Incoming mails from outlook I was able to see multiple Body items, one of which contained the HTML part.However I was still not able to access it via getMIMEEntity.
The mails I created from lotus notes, do not have multiple Body items. When I receive the mails from Lotus Notes > Outlook and I inspect source in Outlook, I see it as HTML. So I assume there is a place where this conversion takes place.
ShelfSession.getInstance().localSession.setConvertMime(false);
MIMEEntity nMime = (MIMEEntity) doc.getMIMEEntity("Body");
I want the Mime part to be set to this variable so I can retrieve the content to form the HTML file.
Please help with any code suggestions or is there some Lotus notes setting that I have missed out on that is making the Mime variable always null?
You said, "The mails I created from lotus notes, do not have multiple Body items." This almost certainly means the Body item is stored as rich text instead of MIME. You can confirm this by looking at the document properties in Notes.
You can use document.convertToMIME() to convert a Body item from Notes rich text to MIME. Here's an example:
MIMEEntity mimeEntity = null;
Item item = document.getFirstItem("Body");
if (item != null) {
if (item.getType() == Item.RICHTEXT) {
// Convert Notes rich text to MIME
document.convertToMIME(Document.CVT_RT_TO_PLAINTEXT_AND_HTML, 0);
}
mimeEntity = document.getMIMEEntity();
}
I've adapted this example from some code in MimeEntityHelper from the XPages Extension Library. I'd encourage you to take a look at that code for more context. For example, you still need to call session.setConvertMIME(false) to avoid converting a document that is already MIME to rich text. The MimeEntityHelper class uses both session.setConvertMIME() and document.convertToMIME() to control document conversions.

ms word file download issue in servlet from unix server to windows

While uploading doc file(example test.doc) to server(unix machine), I am using apache commons jar which gives me FormFile instance at server side which is having all the data in byte array form.
When I write the same byte array to response output stream and send it to browser to download the same file, weird content is shown. I get one pop up to select encoding in which i would like to see the data and weird data is shown in that doc.The content type is set as follows :
response.setContentType("application/msword");
response.setHeader("Content-Disposition", "attachment;filename=test.doc");
I think that while writing data to output stream, meta data related to doc file is also written which causes this issue.
Is there anything specific for doc or docx file formats, which needs to be done so file is in proper format and i can see correct data which i uploaded or I am missing something?
Any help would be appreciated.
Thanks in Advance.
Let me know if more info is required.
There's a known issue in Microsoft which provide workaround for the
Encoding Pop Up
It may not be a fix for your problem because I have not run any test around. But to check the correct mime types please refer to this link:
https://technet.microsoft.com/en-us/library/ee309278(office.12).aspx
Updated:
You can use response type as ArrayBuffer and set the content as Blob.
Blob([response], {type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'});
Or this could work
response.setContentType("application/x-msdownload");
response.setHeader("Content-disposition", "attachment; filename="+ fileName);

Apache James Mail Server - Save attachments on filesystem

I'm using Apache James version 3.0-beta1 and I would like to know if there is a way to save separately the body of the e-mails from the attachments. Right now both of them are saved inside the DB, that leads to a noticeable increase in the table size due to the fact that all the attachments are saved inside the MAIL_BYTES column in the shape of a byte stream.
Is there a way to move outside the DB the attachments and leave inside the DB only the body of the emails? On the long run this default behaviour will make my DB collapse.
You may simply write a mailet to get the attachments of the mail and then save them to a specific folder in your filesystem. To be more specific, in mailet, get the MimeMessage from org.apache.mailet.Mail, then use it to check if there are any attachments by using getFileName() method. This method returns file names if Disposition and ContentType headers are not null . If the result is not null, then that means in than bodyPart you have a file attached.Then using getInputStream() you can save it to anywhere you want.

Java mail PDF attachment not working

I am generating a PDF and trying to attach it to a mail as well as download it from browser using java. Download from browser works fine, but attaching to mail is where I am facing an issue. The file is attached. Attachment name and size of the file are intact. The problem is when I open the PDF from mail attachment, it shows nothing. correct number of pages with no content. When I attach the file downloaded from browser by hardcoding, it works fine. So I suppose the problem is not with the PDF generation. I tried opening both(one downloaded from browser and the other downloaded from mail) the files using comparing tool beyond compare. The one downloaded from mail shows conversion error. When I open with notepad++, both show different encoding. I not very familiar with these encoding thing. I suppose it is something to do with encoding.
I also observed that the content in mail download is same as the one at PDF generation. But the one at browser download is different.
An excerpt of what I get on browser download is as below(The content is too large to paste)
%PDF-1.4
%âãÏÓ
4 0 obj <</Type/XObject/ColorSpace/DeviceRGB/Subtype/Image/BitsPerComponent 8/Width 193/Length 11222/Height 58/Filter/DCTDecode>>stream
ÿØÿà
An excerpt of what I get on mail download is as below
%PDF-1.4
%????
4 0 obj <</Type/XObject/ColorSpace/DeviceRGB/Subtype/Image/BitsPerComponent 8/Width 193/Length 11222/Height 58/Filter/DCTDecode>>stream
????
I am using Spring MimeMessageHelper to send the message. I am using the below method to add attachment
MimeMessageHelper.addAttachment(fileName, new ByteArrayResource(attachmentContent.getBytes()), "application/pdf");
I've also tried another way of attaching but in vain
DataSource dataSource = new ByteArrayDataSource(bytes, "application/pdf");
MimeBodyPart pdfBodyPart = new MimeBodyPart();
pdfBodyPart.addHeader("Content-Type", "application/pdf;charset=UTF-8");
pdfBodyPart.addHeader("Content-disposition", "attachment; filename="+fileName);
pdfBodyPart.setDataHandler(new DataHandler(dataSource));
pdfBodyPart.setFileName(fileName);
mimeMessageHelper.getMimeMultipart().addBodyPart(pdfBodyPart);
Any help would be greatly appreciated. Thanks in advance
I'm not sure if this has anything to do with it but I noticed you're not setting the actual charset in pdfBodyPart.addHeader("Content-Type", "application/pdf;charset");, nor are you calling attachmentContent.getBytes() with a charset as parameter. How is it supposed to know which one you want to use?
What Content-Transfer-Encoding is being used for the attachment in the message you receive? Normally JavaMail will choose an appropriate value, but if document contains an unusual mix of plain text and binary, as your document seems to, JavaMail may not choose the best encoding. You can try adding pdfBodyPart.setHeader("Content-Transfer-Encoding", "base64");
I found out why it was'nt working. It is an encoding issue but nothing to do with MimeMessageHelper. The problem was I generated the PDF to an OutputStream and converted it to String and then converted it into byte array. When I converted to it to String the encoding changed resulting in the issue. So i fixed it by getting byte array from outputStream :)

Naming my inline pdf

I am creating a pdf in a java servlet, and when my created pdf opens it incorrectly names that pdf after my servlet. Here is my code:
response.setHeader(contentDisposition, "inline; filename=TemporaryVerification.pdf");
try {
reader = new PdfReader(CreateStuVerification.class.getResource("/resource/" + tempFile));
stamp = new PdfStamper(reader, response.getOutputStream());
So I want my pdf to be named "TemporaryVerification.pdf", but it is name "CreateStuVerification.pdf"(which is the name of my servlet). Does anyone know why this is, and possibly how to correct it?
EDIT: I do have to keep it as an inline pdf. Though when I tried it as an attachment, it was correctly named.
This behavior is specific to the IE browser. It uses the last part of the URI path as default name of the downloaded resource. The more sane browsers properly use the filename attribute of the Content-Disposition header for this.
You'd better remap your servlet on a path pattern such as /pdf/* and then append the desired filename straight into the URL which is supposed to return the PDF like so
<a href="pdf/TemporaryVerification.pdf">
You can if necessary get the filename part in the servlet as follows:
String filename = request.getPathInfo().substring(1); // TemporaryVerification.pdf
// ...

Categories