Attachments

A collection of Attachment objects.

Properties

The following table lists properties along with their access and descriptions.

Property

Access

Description

Application

R/O

Application. The Application object.

Count

R/O

Long. The number of objects in this collection.

_NewEnum

R/O

Enumeration object. Implements IEnumVARIANT. For Windows only.

Parent

R/O

Message. The Message object that owns this collection.

Methods

Attachment Add(String Filename, [AttachmentTypeConstants ObjType], [String DisplayName])

Adds an existing message as an attachment to the message that owns this collection. The owning message's BoxType must be egwDraft or egwPersonal. Any other BoxType results in an exception being thrown. Creates a new Attachment object and adds it to the collection.

  • The new attachment's Message property is set to Message

  • Its ObjType property is set to egwMessage

  • Its DisplayName property is set to DisplayName.

Attachment Add(Message Message, [String DisplayName])

Adds an existing file as an attachment to the message that owns this collection. The owning message’s BoxType must be egwDraft or egwPersonal. Any other BoxType results in an exception being thrown. Creates a new Attachment object and adds it to the collection.

  • The new attachment’s Filename property is set to Filename

  • Its ObjType property is set to ObjType (File is assumed if ObjType is omitted)

  • Its DisplayName property is set to DisplayName. ObjType cannot be egwMessage.

Attachment Item(VARIANT Index)

DEFAULT. Returns the Attachment object specified by Index. Index may be a Long, a string, or a Message object. If Index is a Long, returns the Attachment object located at the given Index in the collection. Valid indexes are 1 through Count, inclusive. Throws an exception if the Index is outside of this range. If Index is a string, it represents the MessageID of the desired attachment. If Index is a Message object, it represents the desired Message object attachment.

Attachment AddEx(GWStream Stream, [String DisplayName], [String ContentType], [String ContentId])

Creates a new Attachment object and adds it to the collection. To use this version of the method, you must first get a GWStream object using the Stream() method. You write the attachment data into the GWStream object using the GWStream. Write() method.

  • The Stream object must already be filled with the attachment data before the AddEx() method is called.

  • The ObjType can only be File.

  • Its DisplayedName property is set to DisplayName.

  • ContentType is the MIME Content-Type of the attachment.

  • ContentId is the MIME Content-ID of the attachment.

Attachment AddEx(String Filename, [String DisplayName], [String ContentType], [String ContentId])

Creates a new Attachment object and adds it to the collection.

  • The new attachment’s FileName property is set to Filename.

  • The ObjType can only be File.

  • Its DisplayName property is set to DisplayName. If the DisplayName is omitted, the Filename will be used for the DisplayName (minus the path portion).

  • ContentType is the MIME Content-Type of the attachment.

  • ContentId is the MIME Content-ID of the attachment.

GWStream Stream()

Creates a GWStreaming object. Once you have the object, you use the Write() method ti write the attachment data into the object. You can then pass the GWStream object into the AddEx() method.

Remarks

The Add method template is as follows:

Add(VARIANT P1, [VARIANT P2], [VARIANT P3])

The Add method checks the P1 type at runtime.

  • If P1 is an string, the first form of Add is assumed; P2, if present, must be an ObjType Enum of type AttachmentTypeConstants, and P3 if present, must be a string.

  • If P1 is a Message object, the second form of Add is assumed; P2 if present, must be a string, P3 must not be present.

An Attachments collection is refreshed when its parent object is refreshed. When an Attachments collection is refreshed, it recursively refreshes its contained Attachment objects.

Also see Annotate under Methods for the Message object, which adds an existing personal Note as an attachment.

In the past, the user of the ObjectAPI had no way to write a HTML message body (they always has to do a message body in plain text). For the GroupWise Client to understand the message body as being an HTML message body, the message body had to have certain characteristics. The HTML message body needed to be an attachment. The message body attachment name is required to be “text.htm”. The message body has to be the MIME type (ContentType):”text/html”. The AddEx method allows the user to specify those parameters.

It is also possible for the HTML message body to have embedded graphics. The text.htm file has references to those separate graphic files. The text.htm file uses the ContentId to reference the graphics. You then add the external graphic files as a separate attachment. You specify the ContentType and ContentId. The HTML message body is comprised of the text.htm attachment and any referenced graphics file attachment that have a ContentId. The client reads in the text.htm attachment and any following attachment until there is to dump out the attachments on an item that has an HTML message body using the ObjectAPI.

The AddEx method gives the user a way to stream in an attachment without writing the data to a file. For example, if the application wanted to format a HTML message body but not first write the data to a file, they can use the Stream method. You first get a stream (Gstream) object using the Stream() method. You write your attachment data to the stream using the GWStream. Write() method. You then pass the stream object in as the FileName parameter of the AddEx method.

Here is a sample HTML message body:

<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META content="MSHTML 6.00.6001.18148" name=GENERATOR></HEAD>
<BODY style="MARGIN:4px 4px 1px; FONT: 10pt Segoe UI">
<DIV><STRONG>This is a test.</STRONG></DIV>
<DIV><STRONG><IMG alt=""hspace=0 src="cid:GUXBDAUKAFTL.smaller.bmp" align=baseline border=0></STRONG></DIV></BODY></HTML>

Here is output of a simple program to list the attachments:

Figure 3-1 Attachments list

Here is a code snippet that produces the message box:

Private Sub btnTest_Click()
   Dim gwAcct As Account9
   Dim gwApp As Application5
   Dim gwAttach As Attachment3
   Dim gwAttachs As Attachments2
   Dim gwMessage As Message3
   Dim gwMessages As Messages3
   Dim str As String
   str = "/ipa-" + txtServer.Text + " /ipp-" + txtPort.Text

   Set gwApp =CreatedObject("NovellGroupwareSession")
   Set gwAcct = gwApp.MultiLogin(txtUserId.Text, str, txtPassword.Text)
   Set gwFolder = gwAcct.MailBox
   Set gwMessages = gwFolder.Messages
   For Each gwMessage In gwMessages
      If gwMessage.Subject.PlainText = txtSubject.Text Then
         str = "Subject: " & txtSugject.Text Then
         Set gwAttachs = gwMessage.Attachments
         For Each gwAttach In gwAttachs
            str = str & chr(9) & "Name: " & gwAttach.DisplayName & chr(10)
            str = str & chr(9) & "Type: " & gwAttach.ContentType & chr(10)
            If "" <> gwAttachment.ContentId Then
               str = str & chr(9) & "Id: " & gwAttach.ContentId & chr(10)
            End If
            str = str & chr(10)
         Next
         MsgBox str
         Exit For
      End If
   Next
   Set gwAttach = Nothing
   Set gwAttachs = Nothing
   Set gwMessage = Nothing
   Set gwMessages = Nothing
   Set gwFolder = Nothing
   Set gwAcct = Nothing
   Set gwApp = Nothing
End Sub