summaryrefslogtreecommitdiffstats
path: root/src/sigtool.cpp
blob: 3568503e92b3ccacbb451a6861254fb93e3c478b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
 * Copyright (C) 2004 Robert Hogan <robert at roberthogan dot net>
 */

#include "sigtool.h"


#include <tdelocale.h>
#include <kstatusbar.h>
#include <tdefiledialog.h>



#include <kurlrequester.h>
#include <tqlayout.h>
#include <tdemessagebox.h>
#include <tqtextbrowser.h>

const char *mail_clients[] = {
    "KMail",
    "Evolution",
    0
};

Sigtool::Sigtool(TQWidget *parent, const char *name)
    : TQWidget(parent, name)
{

	TQVBoxLayout *vbox = new TQVBoxLayout(this, KDialog::marginHint(),
		KDialog::spacingHint(), "vbox");
	

	//KMessageBox::information (this,nooffilters);
	TQGroupBox *mail_group = new TQGroupBox(i18n("Email Client"), this);
	vbox->addWidget(mail_group);


	TQGridLayout *mail_layout = new TQGridLayout( mail_group, 2, 6, KDialog::spacingHint(),
			KDialog::spacingHint(), "mail_layout");
	mail_layout->addRowSpacing(0, mail_group->fontMetrics().height());
	mail_layout->setColStretch(1, 1);
	mail_layout->setColStretch(2, 1);

	//IP Address & Port
	TQWidget *mail_hlp = new TQWidget( mail_group );

	mail_layout->addMultiCellWidget(mail_hlp, 1,2, 1,6);
	TQGridLayout *mail_dir_layout = new TQGridLayout(mail_hlp,2,6, KDialog::spacingHint() );

	TQLabel *mail_dir_label = new TQLabel(i18n("Choose your email client:"), mail_hlp);
	mail_dir_label->setAlignment(TQt::AlignRight);
	//mail_dir_label->setFixedSize(mail_dir_label->sizeHint());
	mail_dir_layout->addWidget(mail_dir_label,0,2);
	
	check_combo = new TQComboBox(false, mail_hlp);
	check_combo->insertStrList(mail_clients);
	check_combo->adjustSize();
	//check_combo->setFixedSize(check_combo->size());
	mail_dir_layout->addWidget(check_combo,0,3);

	//User & Pass
// 	TQWidget *mail_hlp2 = new TQWidget( mail_group );
// 	mail_layout->addMultiCellWidget(mail_hlp2, 2,2, 1,2);
// 	TQHBoxLayout *mail_userpass_layout = new TQHBoxLayout(mail_hlp2, KDialog::spacingHint() );

        search_button = new TQPushButton (i18n( "Configure Automatically" ), mail_hlp);
        mail_dir_layout->addWidget(search_button,1,2);
        //search_button->setFixedSize(search_button->sizeHint());
    
        manual_button = new TQPushButton (i18n( "Tell me how to do it" ), mail_hlp);
        mail_dir_layout->addWidget(manual_button,1,3);
        //manual_button->setFixedSize(manual_button->sizeHint());


// 	KButtonBox *actionbox = new KButtonBox(mail_hlp, TQt::Horizontal);
// 	mail_userpass_layout->addWidget(actionbox);
// 	actionbox->addStretch();
// 	search_button = actionbox->addButton(i18n("&Configure Automatically"));
// 	manual_button = actionbox->addButton(i18n("&Tell me how to do it"));
// 	actionbox->addStretch();
// 	actionbox->layout();


	
	const TQString text = i18n( "This will help you configure your email client to scan incoming and outgoing mail with KlamAV. Not all mail clients are fully supported yet. Infected mail is clearly marked as such and is wrapped in another email from KlamAV telling you the name of the virus and other relevant details." );
	
	TQGroupBox *Notes = new TQGroupBox(i18n("Notes"), this);
	vbox->addWidget(Notes);
	
	TQGridLayout *notes_layout = new TQGridLayout( Notes, 5, 2, KDialog::spacingHint(),
			KDialog::spacingHint(), "notes_layout");
	notes_layout->addRowSpacing(0, Notes->fontMetrics().height());
	notes_layout->setColStretch(0, 1);
	notes_layout->setColStretch(1, 1);


	TQWidget *notes_hlp = new TQWidget( Notes );

	notes_layout->addMultiCellWidget(notes_hlp, 1,1, 0,1);
	TQHBoxLayout *notes_box = new TQHBoxLayout(notes_hlp, KDialog::spacingHint() );
	
	notes_browser = new TQTextBrowser(notes_hlp);
	notes_browser->setText(text);
	notes_browser->setAlignment( TQt::AlignCenter );
	notes_box->addWidget(notes_browser);

	


	
	
	connect( search_button, SIGNAL(clicked()),
		SLOT(configureKMail()) );
	connect( manual_button, SIGNAL(clicked()),
		SLOT(manual()) );
	connect( check_combo, SIGNAL(activated(const TQString &)),
		SLOT(dobuttons()) );

		


}

Sigtool::~Sigtool()
{
}


void  Sigtool::configureKMail(){

	KMessageBox::information (this,i18n( "Please ensure KMail is not open before we proceed.") );
	
	TQString DatabaseLocation;
	config = TDEGlobal::config();
	config->setGroup("Freshklam");
	TQStringList lastDownloadPaths = config->readListEntry("lastDownloadPaths");
	for (TQStringList::Iterator it = lastDownloadPaths.begin(); it == lastDownloadPaths.begin() ; it++){
			DatabaseLocation = *it;
	}

	config = new TDEConfig("kmailrc");
	config->setGroup("General");
	TQVariant nooffilters = config->readEntry("filters");
	
	int numfilters = nooffilters.toInt();
	nooffilters = numfilters;
	for (int j=0; j != numfilters; j++ ){
		TQVariant numb = j;
		TQString filtername=TQString("Filter #%1").arg(numb.toString());
		config->setGroup(filtername);
		TQString binary = config->readEntry("action-args-0");
		if (binary.find("klammail") != -1){
				KMessageBox::information (this,i18n( "You're already set up! Sure you haven't already configured KMail for KlamAV scanning?") );
				return;
		}
	}

	
	TQString filtername=TQString("Filter #%1").arg(nooffilters.toString());
	config->setGroup(filtername);
	
	config->writeEntry("ConfigureShortcut", "false");
	config->writeEntry("Icon", "");
	config->writeEntry("StopProcessingHere","false");
	config->writeEntry("action-args-0", TQString("klammail -d %1").arg(DatabaseLocation));
	config->writeEntry("action-name-0","filter app");
	config->writeEntry("actions","1");
	config->writeEntry("apply-on","check-mail","manual-filtering");
	config->writeEntry("contentsA","2");
	config->writeEntry("fieldA","<size>");
	config->writeEntry("funcA","greater-or-equal");
	config->writeEntry("name","<<size>>:2");
	config->writeEntry("operator","or");
	config->writeEntry("rules","1");

	numfilters++;
	nooffilters = numfilters;
	filtername=TQString("Filter #%1").arg(nooffilters.toString());
	config->setGroup(filtername);

	config->writeEntry("ConfigureShortcut","false");
	config->writeEntry("Icon", "");
	config->writeEntry("StopProcessingHere","false");
	config->writeEntry("action-args-0","trash");
	config->writeEntry("action-name-0","transfer");
	config->writeEntry("actions","1");
	config->writeEntry("apply-on","check-mail","manual-filtering");
	config->writeEntry("contentsA","virus-found");
	config->writeEntry("fieldA","<any header>");
	config->writeEntry("funcA","contains");
	config->writeEntry("name","<<any header>>:virus-found");
	config->writeEntry("operator","or");
	config->writeEntry("rules","1");

	numfilters ++;
	nooffilters = numfilters;
	config->setGroup("General");
	config->writeEntry("filters", nooffilters.toString());
	config->sync();
	
	KMessageBox::information (this,i18n( "I've set up the filters as the last two in your KMail filter list. You might want to open Kmail up and take a look.") );
}

void  Sigtool::manualKMail(){


	const TQString text = i18n( "Mail scanning support is provided by a program called 'klammail'. This was installed automatically as part of the KlamAV installation. To use this program to scan your email as you send and receive it you need to set up a 'filter' in KMail to 'pipe' mail through klammail as it is coming in/going out. You should then set up a filter after this one to put any mail with the word 'virus-found' in the header into the quarantine folder of your choice. The mail will be clearly marked as infected and will tell you the name of the virus and who the mail is from." );

	notes_browser->setText( text );

	
}

void  Sigtool::manualEvolution(){

	const TQString text = i18n( "Mail scanning support is provided by a program called 'klammail'. This was installed automatically as part of the KlamAV installation. To use this program to scan your email as you send and receive it you need to set up a 'filter' in Evolution to 'pipe' mail through klammail as it is coming in/going out. You should then set up a filter after this one to put any mail with the word 'virus-found' in the header into the quarantine folder of your choice. The mail will be clearly marked as infected and will tell you the name of the virus and who the mail is from." );

	notes_browser->setText( text );
	notes_browser->setAlignment( TQt::AlignCenter );

	
}

void  Sigtool::manual(){

	
	switch (check_combo->currentItem()) {
        case 0 : manualKMail();break;
        case 1 : manualEvolution(); break;
	}


	
}

void  Sigtool::dobuttons(){

	//KMessageBox::information (this,check_combo->currentItem());
	switch (check_combo->currentItem()) {
        case 0 : search_button->setEnabled(true);;break;
        case 1 : search_button->setEnabled(false);; break;
	}


	
}

#include "sigtool.moc"