1
+ using System ;
2
+ using System . Linq ;
3
+ using System . Xml . Serialization ;
4
+ using System . Data ;
5
+ using System . Windows . Forms ;
6
+ using System . Collections . Generic ;
7
+ using taskt . UI . Forms ;
8
+ using taskt . UI . CustomControls ;
9
+ using Microsoft . Office . Interop . Outlook ;
10
+ using Application = Microsoft . Office . Interop . Outlook . Application ;
11
+
12
+ namespace taskt . Core . Automation . Commands
13
+ {
14
+ [ Serializable ]
15
+ [ Attributes . ClassAttributes . Group ( "Outlook Commands" ) ]
16
+ [ Attributes . ClassAttributes . Description ( "This command allows you to manipulate emails with outlook" ) ]
17
+ [ Attributes . ClassAttributes . UsesDescription ( "Use this command when you want to manipulate emails with your currenty logged in outlook account" ) ]
18
+ [ Attributes . ClassAttributes . ImplementationDescription ( "" ) ]
19
+
20
+ public class OutlookDeleteEmailsCommand : ScriptCommand
21
+ {
22
+ [ XmlAttribute ]
23
+ [ Attributes . PropertyAttributes . PropertyDescription ( "Provide the source mail folder name" ) ]
24
+ [ Attributes . PropertyAttributes . InputSpecification ( "Enter the mail folder you want your emails to come from" ) ]
25
+ [ Attributes . PropertyAttributes . SampleUsage ( "**myData**" ) ]
26
+ [ Attributes . PropertyAttributes . Remarks ( "" ) ]
27
+ [ Attributes . PropertyAttributes . PropertyUIHelper ( Attributes . PropertyAttributes . PropertyUIHelper . UIAdditionalHelperType . ShowVariableHelper ) ]
28
+ public string v_SourceFolder { get ; set ; }
29
+
30
+ [ XmlAttribute ]
31
+ [ Attributes . PropertyAttributes . PropertyDescription ( "Provide a filter (Optional)" ) ]
32
+ [ Attributes . PropertyAttributes . InputSpecification ( "Enter an outlook filter string" ) ]
33
+ [ Attributes . PropertyAttributes . SampleUsage ( "[Subject] = 'Hello'" ) ]
34
+ [ Attributes . PropertyAttributes . Remarks ( "" ) ]
35
+ [ Attributes . PropertyAttributes . PropertyUIHelper ( Attributes . PropertyAttributes . PropertyUIHelper . UIAdditionalHelperType . ShowVariableHelper ) ]
36
+ public string v_Filter { get ; set ; }
37
+
38
+ [ XmlAttribute ]
39
+ [ Attributes . PropertyAttributes . PropertyDescription ( "Delete read emails only" ) ]
40
+ [ Attributes . PropertyAttributes . PropertyUISelectionOption ( "Yes" ) ]
41
+ [ Attributes . PropertyAttributes . PropertyUISelectionOption ( "No" ) ]
42
+ [ Attributes . PropertyAttributes . InputSpecification ( "Specify whether to delete read email messages only" ) ]
43
+ [ Attributes . PropertyAttributes . SampleUsage ( "Select **Yes** or **No**" ) ]
44
+ [ Attributes . PropertyAttributes . Remarks ( "" ) ]
45
+ public string v_DeleteReadOnly { get ; set ; }
46
+
47
+ public OutlookDeleteEmailsCommand ( )
48
+ {
49
+ this . CommandName = "OutlookDeleteEmailsCommand" ;
50
+ this . SelectionName = "Delete Outlook Emails" ;
51
+ this . CommandEnabled = true ;
52
+ this . CustomRendering = true ;
53
+ }
54
+ public override void RunCommand ( object sender )
55
+ {
56
+ var engine = ( Engine . AutomationEngineInstance ) sender ;
57
+ var vSourceFolder = v_SourceFolder . ConvertToUserVariable ( sender ) ;
58
+ var vFilter = v_Filter . ConvertToUserVariable ( sender ) ;
59
+
60
+ Application outlookApp = new Application ( ) ;
61
+ AddressEntry currentUser = outlookApp . Session . CurrentUser . AddressEntry ;
62
+ NameSpace test = outlookApp . GetNamespace ( "MAPI" ) ;
63
+
64
+ if ( currentUser . Type == "EX" )
65
+ {
66
+ MAPIFolder inboxFolder = test . GetDefaultFolder ( OlDefaultFolders . olFolderInbox ) . Parent ;
67
+ MAPIFolder sourceFolder = inboxFolder . Folders [ vSourceFolder ] ;
68
+ Items filteredItems = null ;
69
+
70
+ if ( vFilter != "" )
71
+ {
72
+ filteredItems = sourceFolder . Items . Restrict ( vFilter ) ;
73
+ }
74
+ else
75
+ {
76
+ filteredItems = sourceFolder . Items ;
77
+ }
78
+
79
+ List < MailItem > tempItems = new List < MailItem > ( ) ;
80
+ foreach ( object _obj in filteredItems )
81
+ {
82
+ if ( _obj is MailItem )
83
+ {
84
+ MailItem tempMail = ( MailItem ) _obj ;
85
+
86
+ if ( v_DeleteReadOnly == "Yes" )
87
+ {
88
+ if ( tempMail . UnRead == false )
89
+ {
90
+ tempItems . Add ( tempMail ) ;
91
+ }
92
+ }
93
+ else
94
+ {
95
+ tempItems . Add ( tempMail ) ;
96
+ }
97
+ }
98
+ }
99
+ int count = tempItems . Count ;
100
+ for ( int i = 0 ; i < count ; i ++ )
101
+ {
102
+ tempItems [ i ] . Delete ( ) ;
103
+ }
104
+ }
105
+ }
106
+
107
+ public override List < Control > Render ( frmCommandEditor editor )
108
+ {
109
+ base . Render ( editor ) ;
110
+ RenderedControls . AddRange ( CommandControls . CreateDefaultInputGroupFor ( "v_SourceFolder" , this , editor ) ) ;
111
+ RenderedControls . AddRange ( CommandControls . CreateDefaultInputGroupFor ( "v_Filter" , this , editor ) ) ;
112
+ RenderedControls . AddRange ( CommandControls . CreateDefaultDropdownGroupFor ( "v_DeleteReadOnly" , this , editor ) ) ;
113
+ return RenderedControls ;
114
+ }
115
+
116
+ public override string GetDisplayValue ( )
117
+ {
118
+ return base . GetDisplayValue ( ) + $ " [From: { v_SourceFolder } ]";
119
+ }
120
+ }
121
+ }
0 commit comments