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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
// kmacctlocal.cpp
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "kmacctlocal.h"
#include "kmfoldermbox.h"
#include "kmacctfolder.h"
#include "broadcaststatus.h"
using KPIM::BroadcastStatus;
#include "progressmanager.h"
using KPIM::ProgressManager;
#include "kmfoldermgr.h"
#include <kapplication.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kdebug.h>
#include <kconfig.h>
#include <tqfileinfo.h>
#include <tqstylesheet.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <assert.h>
//-----------------------------------------------------------------------------
KMAcctLocal::KMAcctLocal(AccountManager* aOwner, const TQString& aAccountName, uint id):
KMAccount(aOwner, aAccountName, id), mHasNewMail( false ),
mAddedOk( true ), mNumMsgs( 0 ),
mMsgsFetched( 0 ), mMailFolder( 0 )
{
mLock = procmail_lockfile;
}
//-----------------------------------------------------------------------------
KMAcctLocal::~KMAcctLocal()
{
}
//-----------------------------------------------------------------------------
TQString KMAcctLocal::type(void) const
{
return "local";
}
//-----------------------------------------------------------------------------
void KMAcctLocal::init() {
KMAccount::init();
}
//-----------------------------------------------------------------------------
void KMAcctLocal::pseudoAssign( const KMAccount * a )
{
KMAccount::pseudoAssign( a );
const KMAcctLocal * l = dynamic_cast<const KMAcctLocal*>( a );
if ( !l ) return;
setLocation( l->location() );
setLockType( l->lockType() );
setProcmailLockFileName( l->procmailLockFileName() );
}
//-----------------------------------------------------------------------------
void KMAcctLocal::processNewMail(bool)
{
mHasNewMail = false;
if ( !preProcess() ) {
return;
}
TQTime t;
t.start();
for ( mMsgsFetched = 0; mMsgsFetched < mNumMsgs; ++mMsgsFetched )
{
if ( !fetchMsg() )
break;
if (t.elapsed() >= 200) { //hardwired constant
kapp->processEvents();
t.start();
}
}
postProcess();
}
//-----------------------------------------------------------------------------
bool KMAcctLocal::preProcess()
{
if ( precommand().isEmpty() ) {
TQFileInfo fi( location() );
if ( fi.size() == 0 ) {
BroadcastStatus::instance()->seStatusMsgTransmissionCompleted( mName, 0 );
checkDone( mHasNewMail, CheckOK );
return false;
}
}
mMailFolder = new KMFolder( 0, location(), KMFolderTypeMbox,
false /* no index */, false /* don't export sernums */ );
KMFolderMbox* mboxStorage =
static_cast<KMFolderMbox*>(mMailFolder->storage());
mboxStorage->setLockType( mLock );
if ( mLock == procmail_lockfile)
mboxStorage->setProcmailLockFileName( mProcmailLockFileName );
if (!mFolder) {
checkDone( mHasNewMail, CheckError );
BroadcastStatus::instance()->seStatusMsg( i18n( "Transmission failed." ));
return false;
}
//BroadcastStatus::instance()->reset();
BroadcastStatus::instance()->seStatusMsg(
i18n("Preparing transmission from \"%1\"...").tqarg(mName));
Q_ASSERT( !mMailCheckProgressItem );
TQString escapedName = TQStyleSheet::escape( mName );
mMailCheckProgressItem = KPIM::ProgressManager::createProgressItem(
"MailCheck" + mName,
escapedName,
i18n("Preparing transmission from \"%1\"...").tqarg( escapedName ),
false, // cannot be canceled
false ); // no tls/ssl
// run the precommand
if (!runPrecommand(precommand()))
{
kdDebug(5006) << "cannot run precommand " << precommand() << endl;
checkDone( mHasNewMail, CheckError );
BroadcastStatus::instance()->seStatusMsg( i18n( "Running precommand failed." ));
return false;
}
const int rc = mMailFolder->open("acctlocalMail");
if ( rc != 0 ) {
TQString aStr;
aStr = i18n("Cannot open file:");
aStr += mMailFolder->path()+"/"+mMailFolder->name();
KMessageBox::sorry(0, aStr);
kdDebug(5006) << "cannot open file " << mMailFolder->path() << "/"
<< mMailFolder->name() << endl;
checkDone( mHasNewMail, CheckError );
BroadcastStatus::instance()->seStatusMsg( i18n( "Transmission failed." ));
return false;
}
if (!mboxStorage->isLocked()) {
kdDebug(5006) << "mailFolder could not be locked" << endl;
mMailFolder->close("acctlocalMail");
checkDone( mHasNewMail, CheckError );
TQString errMsg = i18n( "Transmission failed: Could not lock %1." )
.tqarg( mMailFolder->location() );
BroadcastStatus::instance()->seStatusMsg( errMsg );
return false;
}
mFolder->open("acctlocalFold");
mNumMsgs = mMailFolder->count();
mMailCheckProgressItem->setTotalItems( mNumMsgs );
// prepare the static parts of the status message:
mStatusMsgStub = i18n("Moving message %3 of %2 from %1.")
.tqarg(mMailFolder->location()).tqarg( mNumMsgs );
//BroadcastStatus::instance()->seStatusProgressEnable( "L" + mName, true );
return true;
}
//-----------------------------------------------------------------------------
bool KMAcctLocal::fetchMsg()
{
KMMessage* msg;
/* This causes mail eating
if (kmkernel->mailCheckAborted()) break; */
const TQString statusMsg = mStatusMsgStub.tqarg( mMsgsFetched );
//BroadcastStatus::instance()->seStatusMsg( statusMsg );
mMailCheckProgressItem->incCompletedItems();
mMailCheckProgressItem->updateProgress();
mMailCheckProgressItem->setqStatus( statusMsg );
msg = mMailFolder->take(0);
if (msg)
{
#if 0
// debug code, don't remove
TQFile fileD0( "testdat_xx-0-0" );
if( fileD0.open( IO_WriteOnly ) ) {
TQCString s = msg->asString();
uint l = s.length();
if ( l > 0 ) {
TQDataStream ds( &fileD0 );
ds.writeRawBytes( s.data(), l );
}
fileD0.close(); // If data is 0 we just create a zero length file.
}
#endif
msg->setqStatus(msg->headerField("tqStatus").latin1(),
msg->headerField("X-tqStatus").latin1());
msg->setEncryptionStateChar( msg->headerField( "X-KMail-EncryptionState" ).at(0) );
msg->setSignatureStateChar( msg->headerField( "X-KMail-SignatureState" ).at(0));
msg->setComplete(true);
msg->updateAttachmentState();
msg->updateInvitationState();
mAddedOk = processNewMsg(msg);
if (mAddedOk)
mHasNewMail = true;
return mAddedOk;
}
return true;
}
//-----------------------------------------------------------------------------
void KMAcctLocal::postProcess()
{
if (mAddedOk)
{
kmkernel->folderMgr()->syncAllFolders();
const int rc = mMailFolder->expunge();
if ( rc != 0 ) {
KMessageBox::queuedMessageBox( 0, KMessageBox::Information,
i18n( "<qt>Cannot remove mail from "
"mailbox <b>%1</b>:<br>%2</qt>" )
.tqarg( mMailFolder->location() )
.tqarg( strerror( rc ) ) );
}
if( mMailCheckProgressItem ) { // do this only once...
BroadcastStatus::instance()->seStatusMsgTransmissionCompleted( mName, mNumMsgs );
mMailCheckProgressItem->setqStatus(
i18n( "Fetched 1 message from mailbox %1.",
"Fetched %n messages from mailbox %1.",
mNumMsgs ).tqarg( mMailFolder->location() ) );
mMailCheckProgressItem->setComplete();
mMailCheckProgressItem = 0;
}
}
// else warning is written already
mMailFolder->close("acctlocalMail");
delete mMailFolder; mMailFolder = 0;
mFolder->close("acctlocalFold");
checkDone( mHasNewMail, CheckOK );
}
//-----------------------------------------------------------------------------
void KMAcctLocal::readConfig(KConfig& config)
{
KMAccount::readConfig(config);
mLocation = config.readPathEntry("Location", mLocation);
TQString locktype = config.readEntry("LockType", "procmail_lockfile" );
if( locktype == "procmail_lockfile" ) {
mLock = procmail_lockfile;
mProcmailLockFileName = config.readEntry("ProcmailLockFile",
mLocation + ".lock");
} else if( locktype == "mutt_dotlock" )
mLock = mutt_dotlock;
else if( locktype == "mutt_dotlock_privileged" )
mLock = mutt_dotlock_privileged;
else if( locktype == "none" )
mLock = lock_none;
else mLock = FCNTL;
}
//-----------------------------------------------------------------------------
void KMAcctLocal::writeConfig(KConfig& config)
{
KMAccount::writeConfig(config);
config.writePathEntry("Location", mLocation);
TQString st = "fcntl";
if (mLock == procmail_lockfile) st = "procmail_lockfile";
else if (mLock == mutt_dotlock) st = "mutt_dotlock";
else if (mLock == mutt_dotlock_privileged) st = "mutt_dotlock_privileged";
else if (mLock == lock_none) st = "none";
config.writeEntry("LockType", st);
if (mLock == procmail_lockfile) {
config.writeEntry("ProcmailLockFile", mProcmailLockFileName);
}
}
//-----------------------------------------------------------------------------
void KMAcctLocal::setLocation(const TQString& aLocation)
{
mLocation = aLocation;
}
void KMAcctLocal::setProcmailLockFileName(const TQString& s)
{
mProcmailLockFileName = s;
}
|