0

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!

Community
  • 1
  • 1
Daniele Grillo
  • 1,011
  • 4
  • 13
  • 31

2 Answers2

1

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.

stwissel
  • 20,110
  • 6
  • 54
  • 101
  • Tnx you @stwissel but I know that you explane...have you see my code SSJS included in the previus post? – Daniele Grillo Jan 30 '14 at 16:08
  • 1
    Please don't ask us to switch our attention between two posts. If the problems are different enough to require two separate questions, then put the code you are talking about, and an exact description of the current problem you are having with the code into this post. – Richard Schwartz Jan 30 '14 at 20:13
  • ok sorry, for this @Richard Schwartz, I have update the post with the code.. tnx a lot – Daniele Grillo Jan 30 '14 at 23:45
0

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.

Richard Schwartz
  • 14,463
  • 2
  • 23
  • 41
  • 1
    I concur; the example code also includes calls to `doc.closeMIMEEntities(true,"Body")` and `doc.save()`. So earlier in the code it's declared as a `NotesDocument` but being treated as a MIME entity... then later being treated as a document again. It's therefore entirely possible that everything up until those last three lines is functioning correctly, but *looks* like it's failing because the document is not being properly saved. – Tim Tripcony Jan 31 '14 at 02:37
  • I'm also not seeing any `try{}catch{}` blocks... so if anything is failing, at best the error is being sent to the log without an opportunity to inspect the error at runtime and decide how to respond. – Tim Tripcony Jan 31 '14 at 02:43
  • One final note: type declarations in SSJS exist primarily to help Designer provide content assist. I recommend removing them prior to actually running the code; instead, always give variables names that make their purpose obvious. For instance, if `doc` is an email, call it `email`. I'm noticing that `listattachs` is a list of attachments, but you're looping based on `listaallegati.length`, and `listaallegati` is never declared. Unless that variable is defined elsewhere, your `for` will not behave as intended. – Tim Tripcony Jan 31 '14 at 02:51
  • tnx you guys, sorry for this..I have clean my code with change the original so that you understand...Now the code is correct, but the problem is the same of my question...sorry for the code confusing :-/ – Daniele Grillo Jan 31 '14 at 07:37