Move emails from Inbox to certain folder in mail file

Hello,

I want to perform following task.

I want to move 5 days old emails from Inbox to certain folder.

I tried following code, but does not seems to be working

I don’t know how to compare 2 date values?

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view As Notesview



Set Db  = session.CurrentDatabase

Set View = Db.GetView ("($All)")

Set Doc = View.GetLastDocument



Set DateTime1 = New NotesDateTime( "Today" )

Set DateTime2 = New NotesDateTime( "" )

Call DateTime1.AdjustDay( -5)	DateTime2.LSLocalTime = doc.LastModified

DateTime2.LSLocalTime = doc.Created

Do While (Not(Doc Is Nothing)) 

	If DateTime1.TimeDifference(DateTime2) <= Today  Then		

		Call doc.PutInFolder("AA")

		Set Doc = View.GetPrevDocument(doc)

	End If

	

Loop	

End Sub

Any idea what is wrong in this code?

Thanks

MS

Subject: move emails from Inbox to certain folder in mail file

Since timestamps are stored in Notes as doubles, you don’t really need to use the NotesDateTime object at all. Save some effort by just treating the dates and times as numbers. Something like:Dim FiveDaysAgo as Long

FiveDaysAgo = Today - 5

…

if doc.lastModified < FiveDaysAgo then …

Subject: RE: move emails from Inbox to certain folder in mail file

Thanks to you both for your reply.

I tried this code

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view As Notesview

	

Set Db  = session.CurrentDatabase

Set View = Db.GetView ("($Inbox)")

Set Doc = View.GetFirstDocument



Dim vArchiveDate As Variant

vArchiveDate = Datenumber( Year(Today()) , Month(Today()) , Day(Today()) - 5 )



Do While (Not(Doc Is Nothing)) 		

If Fix(doc.DeliveredDate(0)) <= vArchiveDate  Then		

Dim item As NotesItem

Set Doc = View.GetNextDocument(doc)

End If		

Loop	

End Sub

Problem I have is, as per above code, documents does moves to the folder AA but, I also want to delete from $Inbox, how to delete an email after moving to folder AA?

Thanks in advance

MS

Subject: RE: move emails from Inbox to certain folder in mail file

use doc.Putinfolder() to add a doc to a folder; doc.Removefromfolder() to take the doc out of a folder.

Don’t put this line

Set Doc = View.GetNextDocument(doc)

inside an If clause. If the if ever fails, the line will never execute and you’ll have an infinite loop.

As I said in my last post, you are working really hard to take a nice integer Today() and turn it into a Date type stored in vArchiveDate, then you’re forcing the run time to convert this variant back to an integer so it can be compared to another integer (Fix() returns an integer.) You’re also calling the function Today() 3 times, even though your code depends on it returning the same value all 3 times.

Subject: move emails from Inbox to certain folder in mail file

I think the main problem is that you are comparing a number of seconds to a date. Instead of:If DateTime1.TimeDifference(DateTime2) <= Today Then

use:

If DateTime1>DateTime2 Then

Also, why read all documents in $All? Why not just read the ones in the $Inbox?