' Copryright 2002-2003 by Josh Moyer , all rights reserved. Option Strict Off Option Explicit On Friend Class FormVMP Inherits System.Windows.Forms.Form #Region "Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean) If Disposing Then If Not components Is Nothing Then components.Dispose() End If End If MyBase.Dispose(Disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer Public WithEvents Label6 As System.Windows.Forms.Label Public WithEvents Frame1 As System.Windows.Forms.GroupBox 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Public WithEvents PollTimer As System.Windows.Forms.Timer Public WithEvents TrollButton As System.Windows.Forms.Button Private Sub InitializeComponent() Me.components = New System.ComponentModel.Container() Me.PollTimer = New System.Windows.Forms.Timer(Me.components) Me.Frame1 = New System.Windows.Forms.GroupBox() Me.Label6 = New System.Windows.Forms.Label() Me.TrollButton = New System.Windows.Forms.Button() Me.Frame1.SuspendLayout() Me.SuspendLayout() ' 'PollTimer ' Me.PollTimer.Enabled = True Me.PollTimer.Interval = 60000 ' 'Frame1 ' Me.Frame1.BackColor = System.Drawing.SystemColors.Control Me.Frame1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label6}) Me.Frame1.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Frame1.ForeColor = System.Drawing.SystemColors.ControlText Me.Frame1.Location = New System.Drawing.Point(16, 16) Me.Frame1.Name = "Frame1" Me.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Frame1.Size = New System.Drawing.Size(345, 65) Me.Frame1.TabIndex = 1 Me.Frame1.TabStop = False Me.Frame1.Text = "About" ' 'Label6 ' Me.Label6.BackColor = System.Drawing.SystemColors.Control Me.Label6.Cursor = System.Windows.Forms.Cursors.Default Me.Label6.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label6.ForeColor = System.Drawing.SystemColors.ControlText Me.Label6.Location = New System.Drawing.Point(8, 16) Me.Label6.Name = "Label6" Me.Label6.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label6.Size = New System.Drawing.Size(329, 41) Me.Label6.TabIndex = 2 Me.Label6.Text = "The nodomain.net voice mail processor is responsible for processing new voice mai" & _ "l and sending it to the approprate recipients. No user intervention is required" & _ "." ' 'TrollButton ' Me.TrollButton.BackColor = System.Drawing.SystemColors.Control Me.TrollButton.Cursor = System.Windows.Forms.Cursors.Default Me.TrollButton.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.TrollButton.ForeColor = System.Drawing.SystemColors.ControlText Me.TrollButton.Location = New System.Drawing.Point(16, 96) Me.TrollButton.Name = "TrollButton" Me.TrollButton.RightToLeft = System.Windows.Forms.RightToLeft.No Me.TrollButton.Size = New System.Drawing.Size(97, 25) Me.TrollButton.TabIndex = 0 Me.TrollButton.Text = "Troll Mailbox" ' 'FormVMP ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(376, 94) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Frame1, Me.TrollButton}) Me.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Location = New System.Drawing.Point(4, 30) Me.Name = "FormVMP" Me.Text = "nodomain.net Voice Mail Processor" Me.Frame1.ResumeLayout(False) Me.ResumeLayout(False) End Sub #End Region #Region "WinFax constants" Const EVENTTYPE_UNKNOWN As Short = 0 Const EVENTTYPE_LGFOLDER As Short = 1 Const EVENTTYPE_FAX As Short = 2 Const EVENTTYPE_VOICE As Short = 3 Const EVENTTYPE_PBFOLDER As Short = 4 Const EVENTTYPE_USER As Short = 5 Const EVENTTYPE_GROUP As Short = 6 Const STANDARDFOLDER_NONE As Short = 0 Const STANDARDFOLDER_WINFAX_ROOT As Short = 1 Const STANDARDFOLDER_WINFAX_LOG As Short = 2 Const STANDARDFOLDER_WINFAX_RECEIVELOG As Short = 3 Const STANDARDFOLDER_WINFAX_SENDLOG As Short = 4 Const STANDARDFOLDER_WINFAX_WASTEBASKET As Short = 5 Const STANDARDFOLDER_WINFAX_OUTBOX As Short = 6 Const STANDARDFOLDER_MAPI As Short = 7 Const SDKERROR_NOERROR As Short = 0 Const SDKERROR_NOENTRYID As Short = 2 Const SDKERROR_BADENTRYID As Short = 3 Const SDKERROR_BADDATASTRUCT As Short = 4 Const SDKERROR_BADFILESPEC As Short = 5 Const SDKERROR_CANTSETFOLDER As Short = 6 Const SDKERROR_CANTGETCOUNTER As Short = 7 Const SDKERROR_CANTENUMERATE As Short = 8 Const SDKERROR_CANTREMOVE As Short = 9 Const SDKERROR_CANTADD As Short = 10 Const SDKERROR_WRONGEVENTTYPE As Short = 11 Const EVENTSTATUS_UNKNOWN As Short = 2 Const EVENTSTATUS_COMPLETE As Short = 3 Const EVENTSTATUS_FAILED As Short = 4 Const EVENTSTATUS_HOLDING As Short = 5 Const EVENTSTATUS_WAITING_AT_SERVER As Short = 6 Const EVENTSTATUS_RECURRING As Short = 7 Const EVENTSTATUS_SENDING As Short = 8 Const EVENTSTATUS_GROUP_SEND As Short = 9 Const EVENTSTATUS_PENDING As Short = 10 #End Region 'Global Variables Dim MsgID As String ' the ID of the current message Dim FolderID As String ' the ID of the working folder Dim CurrentFolderName As String ' the name of the working folder Dim TargetFolderName As String = "Receive Log" ' the string we match against to see if our working folder is the right one Dim DEBUG_EN As Boolean = False ' Enable debugging? Dim logObj As Object Dim mySmtpServer = "localhost" Private Sub FormVMP_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load ' Init for debugging, if appropraite If DEBUG_EN Then MyBase.Height = CInt(MyBase.Size.Height) + 39 PollTimer.Enabled = False End If 'Initialize the WinFax control logObj = CreateObject("WinFax.SDKLog") ' Set the working folder Dim FolderRootID As String FolderRootID = logObj.GetFolderListFirst(STANDARDFOLDER_WINFAX_ROOT, "0") FolderID = logObj.GetFolderListFirst("0", FolderRootID) If DEBUG_EN Then MsgBox("FolderRootID = " & logObj.GetFolderDisplayName(FolderRootID) & " (" & FolderRootID & ")" & vbLf & _ "FolderID = " & logObj.GetFolderDisplayName(FolderID) & " (" & FolderID & ")") End If If logObj.GetFolderDisplayName(FolderID) <> TargetFolderName Then Do Until CurrentFolderName = TargetFolderName ' Bug: can cause infinite loop if there is no TargetFolderName FolderID = logObj.GetFolderListNext() CurrentFolderName = logObj.GetFolderDisplayName(FolderID) Loop End If End Sub Private Sub PollTimerFire(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles PollTimer.Tick TrollMailbox(PollTimer, New System.EventArgs()) PollTimer.Enabled = True End Sub Private Sub TrollMailbox(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles TrollButton.Click ' Get the first message in the Inbox MsgID = logObj.GetMessageListFirst(STANDARDFOLDER_NONE, FolderID) ' Loop through the messages If DEBUG_EN Then ProcessMessage(MsgID, FolderID) MsgID = logObj.GetMessageListNext() Else Do Until MsgID = "" ProcessMessage(MsgID, FolderID) MsgID = logObj.GetMessageListNext() Loop End If End Sub Private Sub ProcessMessage(ByVal MsgID As String, ByVal FolderID As String) Dim msgObj As New MailMessage() Dim MsgDisplayName As String, _ MsgTime As String, _ MsgDuration As String, _ WFMsgType As Double, _ MsgDate As String, _ MsgNumber As String, _ MsgFromStr As String ' Retrieve the message's properties With logObj MsgDate = .GetMessageDate(MsgID) MsgDisplayName = .GetMessageDisplayName(MsgID) MsgDuration = .GetMessageDuration(MsgID).ToString() MsgNumber = .GetMessageNumber(MsgID) MsgTime = .GetMessageTime(MsgID) WFMsgType = GetMessageType(MsgID) End With ' Parse and rewrite MsgDisplayName Select Case MsgDisplayName Case "O" MsgDisplayName = "UNAVAILABLE" Case "P" MsgDisplayName = "PRIVATE" Case "" MsgDisplayName = "" End Select If MsgDisplayName <> "OUT OF AREA" And MsgDisplayName <> "PRIVATE" And MsgDisplayName <> "UNKNOWN" Then MsgFromStr = MsgDisplayName & " (" & MsgNumber & ") " Else MsgFromStr = MsgDisplayName & " " End If ' Address the message msgObj.From = MsgFromStr If DEBUG_EN Then msgObj.To = """nodomain.net voice messaging system"" " Else msgObj.To = """Josh Moyer"" " End If ' Set the subject If WFMsgType = EVENTTYPE_VOICE Then msgObj.Subject = MsgDisplayName & " left a message" Else msgObj.Subject = MsgDisplayName & " called" End If ' Create the message body msgObj.Body = "nodomain.net voice messaging report" & vbLf & _ vbLf & _ "Caller Name: " & MsgDisplayName & vbLf & _ "Caller Number: " & MsgNumber & vbLf & _ vbLf & _ "Date: " & MsgDate & vbLf & _ "Time: " & MsgTime & vbLf & _ "Call Duration: " & MsgDuration & vbLf & _ "Message Length: NYI" ' Add attachment if this is a voice message Dim attchWFXObjInfo() As String Dim attchName As String If WFMsgType = EVENTTYPE_VOICE Then ' Parse attachment path ' attchWFXObj is a zero-based array and structured as file_name, path, description attchWFXObjInfo = Split(logObj.GetMessageFirstFile(FolderID, MsgID), "|", -1, CompareMethod.Text) ' Add attachment to msgObj Dim attchObj As MailAttachment attchName = attchWFXObjInfo(1) & attchWFXObjInfo(0) Try attchObj = New MailAttachment(attchName) Catch msgObj.Body = msgObj.Body & vbLf & vbLf & "ERROR: Voice message not found." & vbLf & "(" & attchName & ")" End Try If attchObj Is Nothing Then Else Try msgObj.Attachments.Add(attchObj) Catch msgObj.Body = msgObj.Body & vbLf & vbLf & "ERROR: Failed when attempting to add attachment to message." End Try End If End If 'Send it Try SmtpMail.SmtpServer = mySmtpServer SmtpMail.Send(msgObj) Catch MsgBox("SmtpMail.Send() failed, message processing stopped.") msgObj = Nothing MyBase.Close() End Try msgObj = Nothing 'Delete message If DEBUG_EN Then Else logObj.DeleteMessage(MsgID) End If End Sub Private Function GetMessageType(ByVal MsgID As String) As Short Dim FileNameString As String FileNameString = logObj.GetMessageFirstFile(FolderID, MsgID) 'If DEBUG_EN Then 'MsgBox("GetMessageType() Diagnostics:" & vbLf & "FileNameString = " & FileNameString) 'End If If FileNameString <> Nothing Then GetMessageType = EVENTTYPE_VOICE Else GetMessageType = EVENTTYPE_UNKNOWN End If End Function Sub FormVMP_Unload() ' Clean-up logObj = Nothing End Sub End Class