0
votes

this is not only a XPages question, but also a Lotusscript question.

If you have an exist Body MIMEEntity field and you would add for example attachment in Lotuscript Code or Java Code...how can you do it? I have investigate more time without success

Read my previus question to understand the code so you can see for example that I need to attach the attachments from another notes document (or filesystem is the same)

I re-insert the example code (I need to add the attachments from another RT MIME Field to another RT MIME field names Body, but after this code...the output of Body is damaged and show only the new attachments..and lose the original content..someone know why? ):

session.setConvertMime(false);
var doc:NotesDocument=document1.getDocument(true);
var mimeRoot:NotesMIMEEntity=doc.getMIMEEntity("Body");
var docAttach:NotesDocument=database.getDocumentByUNID('XXXXXXXUNID'); //doc where are the attachmetns files MIME or RICHTEXT


var XSPReply=wrapDocument(docAttach);  //function in Xsnippets from Opentntf.org
var listattachs=XSPReply.getAttachmentList("Body");

for (var i=0; i<listattachs.length; i++) {
   var is=null;
   var att = listattachs[i];
   var persistentName = att.getPersistentName()==null?att.getName():att.getPersistentName();
   var cid = att.getCID();
   var eo:NotesEmbeddedObject = docAttach.getAttachment(persistentName);
   if (null != eo) {
      var child:NotesMIMEEntity=mimeRoot.createChildEntity(); //create child of original mail
      var emailHeader:NotesMIMEHeader = child.createHeader("Content-Disposition");
      emailHeader.setHeaderVal("attachment; filename=\"" + persistentName+ "\"");
      emailHeader = child.createHeader("Content-ID");
      emailHeader.setHeaderVal("<" + cid + ">");
      var is = new java.io.BufferedInputStream(eo.getInputStream());
      var stream:NotesStream = session.createStream();
      stream.setContents(is);
      child.setContentFromBytes(stream, att.getType(),NotesMIMEEntity.ENC_IDENTITY_BINARY);
    }
}

doc.closeMIMEEntities(true,"Body")
doc.save()
session.setConvertMime(true);

Seem simple...but I don't find how correctly edit exist my NotesMimeEntity (that is different to create a new NotesMimeEntity)

Tnx you very much!

2

2 Answers

1
votes

A mime entity contains one type of content. So you won't add an attachment to an existing mime entity, but create a sibling or a child entity. Each entity contains one thing. So you will need one entity each for each attachment.

Hope that clarifies it.

Update:
My answer stands: You do not mix content types in a MIME entry. It has ONE type, so no point editing the mime entry, but to create a new one. Edit would be to read the content (which would be text/plain or text/html) into a stream, update it there and write it back. If you want to add an attachment you need to add another MIME part.

0
votes

I'm really not familiar with SSJS (and I can't find a syntax reference in the first few Google hits) but this looks wrong:

var doc:NotesDocument=document1.getDocument().getMIMEEntity("Body");

You are calling getMIMEEntity, which returns type NotesMIMEEntity, but you are assigning it to a var named doc, and I'm assuming that the :NotesDocument is saying that doc has the type NotesDocument. So when you get down to calling doc.createChildEntity I really can't guess what might happen, but I doubt it's going to be something good.