Jump to content

Strange Outlook Problem


 Share

Recommended Posts

Hi, I don't normally ask for help but I'm stuck on this one. I wrote the following code to move anything in my inbox to a SPAM folder if the sender wasn't in my address book. That part works great but for some reason it also copies everything to the 'Deleted Items' folder. Any ideas?

CODE
;*===================================================================*

;* MailMaid -- Move messages from unknown senders to SPAM

;*===================================================================*

;* Created 06/23/07 Ralph D. Schaefer

;* Updated mm/dd/yy

;*===================================================================*

Const $VERSION = "MailMaid v0.1"

#include <file.au3>

#include <outlookconstants.a3h>

Global $g_oContacts

Global $g_oInbox

Global $g_oSpam = 0

Global $g_oNameSpace

Global $g_oOutlook

Global $g_oRoot

Global $g_oSMail

Global $g_aContacts[9999]

Func Quit()

   Exit

EndFunc

Func Init()

Local $oFolder

   $g_oOutlook = ObjGet("", "Outlook.Application")

   If @Error then

      MsgBox(16, $VERSION, "Outlook does not appear to be running")

      Exit

   EndIf

   $g_oNameSpace = $g_oOutlook.GetNameSpace("MAPI")

   $g_oInbox = $g_oNameSpace.GetDefaultFolder($olFolderInbox)

   $g_oContacts = $g_oNameSpace.GetDefaultFolder($olFolderContacts)

   $g_oRoot = $g_oInbox.Parent

   For $oFolder In $g_oRoot.Folders

      If $oFolder.Name = "Spam" then

         $g_oSpam = $oFolder

         ExitLoop

      EndIf

   Next

   If Not IsObj($g_oSpam) then

      $g_oSpam = $g_oRoot.Folders.Add("Spam", $olFolderInbox)

   EndIf

   If Not IsObj($g_oSpam) then

      MsgBox(16, $VERSION, "'SPAM' folder not found, unable to create")

      Exit

   EndIf

   $g_oSMail = ObjCreate("Redemption.SafeMailItem")

EndFunc

Func GetContacts()

   Local $oContact

   Local $iContact

   $g_aContacts[0] = 0

   For $iContact = 1 to $g_oContacts.Items.Count

      $oContact = $g_oContacts.Items($iContact)

      $g_aContacts[$iContact] = $oContact.Email1Address

      $g_aContacts[0] += 1

   Next

EndFunc

Func MoveStrangers()

   Local $oItem

   Local $oSenderAE

   Local $lItems

   Local $iItem

   Local $sFrom

   $lItems = $g_oInbox.Items.Count

   For $iItem = $lItems to 1 Step -1

      $oItem = $g_oInbox.Items($iItem)

      $g_oSMail.Item = $oItem

      $oSenderAE = $g_oSMail.Sender

      If IsObj($oSenderAE) then

   $sFrom = $oSenderAE.Address

   For $iContact = 1 to $g_aContacts[0]

      If $sFrom = $g_aContacts[$iContact] then

         ExitLoop

      EndIf

   Next

         If $iContact > $g_aContacts[0] then

            $oItem.Move($g_oSpam)

         EndIf

      EndIf

      $oSenderAE = 0

      $oItem = 0

   Next

EndFunc

;*===================================================================*

Opt("MustDeclareVars", 1)

HotKeySet("^{F12}", "Quit")

Init()

GetContacts()

MoveStrangers()

Quit()

Link to comment
Share on other sites

Hi,

I also use cdo/redemption scripts and did not notice this strange behavior even for spams using outlook 2k3 / Exchange 2k3sp2, but I'm directly using new redemption sessions for scripts:

ObjCreate("Redemption.RDOSession")

alongside the regular outlook client. Did you try this solution? What version of Outlook do you have? Are you connected to an Exchange server?

Regards,

registry victim

Link to comment
Share on other sites

Hi,

I also use cdo/redemption scripts and did not notice this strange behavior even for spams using outlook 2k3 / Exchange 2k3sp2, but I'm directly using new redemption sessions for scripts:

ObjCreate("Redemption.RDOSession")

alongside the regular outlook client. Did you try this solution? What version of Outlook do you have? Are you connected to an Exchange server?

Regards,

Thanks for the reply. I didn't know you could start a Redemption session, I'll give that a try. Don't laugh, but I'm using Outlook 97. I've been looking for a freeware replacement for a long time. I guess I'm just too picky. Maybe I'll write my own. If I do, I'll share it with everyone here.

Ralph

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...