VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "ArmMail"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Public AddrFrom As Variant
Public AddrTo As Variant
Public AddrCc As Variant
Public AddrBcc As Variant
Public Subject As Variant
Public Body As Variant
Public HTMLCharset As String
Public HTMLBody As Variant
Public Attachments As Collection
Public IsReaded As Boolean
Public IsReportItem As Boolean
'Public Document As Object   'NotesDocument
#If LIVE = 1 Then
Public MailItem As Object   'Outlook mail item
#Else
Public MailItem As Outlook.MailItem   'Outlook mail item
#End If
Public SendFromLocation As String
Public SendAsAccount As String

Public Sub Load_A_COM()
  Set Attachments = New Collection
  IsReportItem = False
End Sub

Public Sub UnLoad_A_COM()
  Set Attachments = Nothing
End Sub

Public Sub SetTextAddrTo(as_TextTo As String)
  Call SplitAddress(as_TextTo, AddrTo)
End Sub

Public Sub SetTextAddrCc(as_TextCc As String)
  Call SplitAddress(as_TextCc, AddrCc)
End Sub

Public Sub SetTextAddrBcc(as_TextBcc As String)
  Call SplitAddress(as_TextBcc, AddrBcc)
End Sub

Public Function GetTextAddrFrom() As String
  If IsArray(AddrFrom) Then
    GetTextAddrFrom = Join(AddrFrom, ",")
  Else
    GetTextAddrFrom = CStr(AddrFrom)
  End If
End Function

Public Function GetTextAddrTo() As String
  If IsArray(AddrTo) Then
    GetTextAddrTo = Join(AddrTo, ",")
  Else
    GetTextAddrTo = CStr(AddrTo)
  End If
End Function

Public Function GetTextAddrCc() As String
  If IsArray(AddrCc) Then
    GetTextAddrCc = Join(AddrCc, ",")
  Else
    GetTextAddrCc = CStr(AddrCc)
  End If
End Function

Public Function GetTextAddrBcc() As String
  If IsArray(AddrBcc) Then
    GetTextAddrBcc = Join(AddrBcc, ",")
  Else
    GetTextAddrBcc = CStr(AddrBcc)
  End If
End Function

Private Sub SplitAddress(as_Text As String, ByRef av_Value As Variant)
Dim ll_Index As Long

  av_Value = Split(as_Text, ",")
  For ll_Index = 0 To UBound(av_Value)
    av_Value(ll_Index) = Trim(av_Value(ll_Index))
  Next
End Sub

Public Function GetAttachment(al_Idx As Long, av_Path As Variant)
On Error GoTo ErrorHandler
  GetAttachment = False
  If Not (MailItem Is Nothing) Then
    MailItem.Attachments.Item(al_Idx).SaveAsFile (av_Path)
    GetAttachment = True
  End If
  Exit Function
ErrorHandler:
  GetAttachment = False
End Function

'Public Function GetMailFormat() As String
'#If LIVE = 1 Then
'Dim Body As Object
' Dim mime As Object
'#Else
'Dim Body As NotesItem
' Dim mime As NotesMIMEEntity
'#End If

'  GetMailFormat = Subject
'        Set Body = Document.GetFirstItem("Body")
'        If Body.Type = MIME_PART Then
'          Set mime = Body.GetMIMEEntity
'          GetMailFormat = "Content type:" & Chr(9) & mime.contentType _
'          & Chr(13) & "Content subtype:" & Chr(9) _
'          & mime.ContentSubType & Chr(13) & "Headers" _
'          & Chr(13) & mime.Headers & Chr(13) _
'          & "Content" & Chr(13) & mime.ContentAsText

'        End If
'End Function

Public Function AddAttachment(ByVal av_AttachmentName As Variant) As Boolean
Dim lb_Found As Boolean
Dim ll_Index As Long
  
  If av_AttachmentName = "" Then
    AddAttachment = False
  Else
    lb_Found = False
    For ll_Index = 1 To Attachments.Count
      If StrComp(av_AttachmentName, Attachments(ll_Index), vbTextCompare) = 0 Then
        lb_Found = True
        Exit For
      End If
    Next
    If Not lb_Found Then
      Call Attachments.Add(av_AttachmentName)
    End If
    AddAttachment = Not lb_Found
  End If
End Function

