7 #include "kmacctlocal.h"
8 #include "kmfoldermbox.h"
9 #include "kmacctfolder.h"
10 #include "broadcaststatus.h"
11 using KPIM::BroadcastStatus;
12 #include "progressmanager.h"
13 using KPIM::ProgressManager;
15 #include "kmfoldermgr.h"
17 #include <tdeapplication.h>
18 #include <tdelocale.h>
19 #include <tdemessagebox.h>
21 #include <tdeconfig.h>
23 #include <tqfileinfo.h>
24 #include <tqstylesheet.h>
32 KMAcctLocal::KMAcctLocal(
AccountManager* aOwner,
const TQString& aAccountName, uint
id):
33 KMAccount(aOwner, aAccountName, id), mHasNewMail( false ),
34 mAddedOk( true ), mNumMsgs( 0 ),
35 mMsgsFetched( 0 ), mMailFolder( 0 )
37 mLock = procmail_lockfile;
42 KMAcctLocal::~KMAcctLocal()
48 TQString KMAcctLocal::type(
void)
const
55 void KMAcctLocal::init() {
61 void KMAcctLocal::pseudoAssign(
const KMAccount * a )
63 KMAccount::pseudoAssign( a );
65 const KMAcctLocal * l =
dynamic_cast<const KMAcctLocal*
>( a );
68 setLocation( l->location() );
69 setLockType( l->lockType() );
70 setProcmailLockFileName( l->procmailLockFileName() );
74 void KMAcctLocal::processNewMail(
bool)
78 if ( !preProcess() ) {
85 for ( mMsgsFetched = 0; mMsgsFetched < mNumMsgs; ++mMsgsFetched )
90 if (t.elapsed() >= 200) {
91 kapp->processEvents();
101 bool KMAcctLocal::preProcess()
103 if ( precommand().isEmpty() ) {
104 TQFileInfo fi( location() );
105 if ( fi.size() == 0 ) {
106 BroadcastStatus::instance()->setStatusMsgTransmissionCompleted( mName, 0 );
107 checkDone( mHasNewMail, CheckOK );
112 mMailFolder =
new KMFolder( 0, location(), KMFolderTypeMbox,
114 KMFolderMbox* mboxStorage =
115 static_cast<KMFolderMbox*
>(mMailFolder->storage());
116 mboxStorage->setLockType( mLock );
117 if ( mLock == procmail_lockfile)
118 mboxStorage->setProcmailLockFileName( mProcmailLockFileName );
121 checkDone( mHasNewMail, CheckError );
122 BroadcastStatus::instance()->setStatusMsg( i18n(
"Transmission failed." ));
127 BroadcastStatus::instance()->setStatusMsg(
128 i18n(
"Preparing transmission from \"%1\"...").arg(mName));
131 Q_ASSERT( !mMailCheckProgressItem );
132 TQString escapedName = TQStyleSheet::escape( mName );
133 mMailCheckProgressItem = KPIM::ProgressManager::createProgressItem(
136 i18n(
"Preparing transmission from \"%1\"...").arg( escapedName ),
141 if (!runPrecommand(precommand()))
143 kdDebug(5006) <<
"cannot run precommand " << precommand() << endl;
144 checkDone( mHasNewMail, CheckError );
145 BroadcastStatus::instance()->setStatusMsg( i18n(
"Running precommand failed." ));
149 const int rc = mMailFolder->open(
"acctlocalMail");
152 aStr = i18n(
"Cannot open file:");
153 aStr += mMailFolder->path()+
"/"+mMailFolder->name();
154 KMessageBox::sorry(0, aStr);
155 kdDebug(5006) <<
"cannot open file " << mMailFolder->path() <<
"/"
156 << mMailFolder->name() << endl;
157 checkDone( mHasNewMail, CheckError );
158 BroadcastStatus::instance()->setStatusMsg( i18n(
"Transmission failed." ));
162 if (!mboxStorage->isLocked()) {
163 kdDebug(5006) <<
"mailFolder could not be locked" << endl;
164 mMailFolder->close(
"acctlocalMail");
165 checkDone( mHasNewMail, CheckError );
166 TQString errMsg = i18n(
"Transmission failed: Could not lock %1." )
167 .arg( mMailFolder->location() );
168 BroadcastStatus::instance()->setStatusMsg( errMsg );
172 mFolder->open(
"acctlocalFold");
174 mNumMsgs = mMailFolder->count();
176 mMailCheckProgressItem->setTotalItems( mNumMsgs );
179 mStatusMsgStub = i18n(
"Moving message %3 of %2 from %1.")
180 .arg(mMailFolder->location()).arg( mNumMsgs );
188 bool KMAcctLocal::fetchMsg()
195 const TQString statusMsg = mStatusMsgStub.arg( mMsgsFetched );
197 mMailCheckProgressItem->incCompletedItems();
198 mMailCheckProgressItem->updateProgress();
199 mMailCheckProgressItem->
setStatus( statusMsg );
201 msg = mMailFolder->take(0);
206 TQFile fileD0(
"testdat_xx-0-0" );
207 if( fileD0.open( IO_WriteOnly ) ) {
211 TQDataStream ds( &fileD0 );
212 ds.writeRawBytes( s.data(), l );
219 msg->setEncryptionStateChar( msg->
headerField(
"X-KMail-EncryptionState" ).at(0) );
220 msg->setSignatureStateChar( msg->
headerField(
"X-KMail-SignatureState" ).at(0));
222 msg->updateAttachmentState();
223 msg->updateInvitationState();
225 mAddedOk = processNewMsg(msg);
237 void KMAcctLocal::postProcess()
241 kmkernel->folderMgr()->syncAllFolders();
242 const int rc = mMailFolder->expunge();
244 KMessageBox::queuedMessageBox( 0, KMessageBox::Information,
245 i18n(
"<qt>Cannot remove mail from "
246 "mailbox <b>%1</b>:<br>%2</qt>" )
247 .arg( mMailFolder->location() )
248 .arg( strerror( rc ) ) );
251 if( mMailCheckProgressItem ) {
252 BroadcastStatus::instance()->setStatusMsgTransmissionCompleted( mName, mNumMsgs );
253 mMailCheckProgressItem->setStatus(
254 i18n(
"Fetched 1 message from mailbox %1.",
255 "Fetched %n messages from mailbox %1.",
256 mNumMsgs ).arg( mMailFolder->location() ) );
257 mMailCheckProgressItem->setComplete();
258 mMailCheckProgressItem = 0;
263 mMailFolder->close(
"acctlocalMail");
264 delete mMailFolder; mMailFolder = 0;
266 mFolder->close(
"acctlocalFold");
268 checkDone( mHasNewMail, CheckOK );
273 void KMAcctLocal::readConfig(TDEConfig& config)
275 KMAccount::readConfig(config);
276 mLocation = config.readPathEntry(
"Location", mLocation);
277 TQString locktype = config.readEntry(
"LockType",
"procmail_lockfile" );
279 if( locktype ==
"procmail_lockfile" ) {
280 mLock = procmail_lockfile;
281 mProcmailLockFileName = config.readEntry(
"ProcmailLockFile",
282 mLocation +
".lock");
283 }
else if( locktype ==
"mutt_dotlock" )
284 mLock = mutt_dotlock;
285 else if( locktype ==
"mutt_dotlock_privileged" )
286 mLock = mutt_dotlock_privileged;
287 else if( locktype ==
"none" )
294 void KMAcctLocal::writeConfig(TDEConfig& config)
296 KMAccount::writeConfig(config);
298 config.writePathEntry(
"Location", mLocation);
300 TQString st =
"fcntl";
301 if (mLock == procmail_lockfile) st =
"procmail_lockfile";
302 else if (mLock == mutt_dotlock) st =
"mutt_dotlock";
303 else if (mLock == mutt_dotlock_privileged) st =
"mutt_dotlock_privileged";
304 else if (mLock == lock_none) st =
"none";
305 config.writeEntry(
"LockType", st);
307 if (mLock == procmail_lockfile) {
308 config.writeEntry(
"ProcmailLockFile", mProcmailLockFileName);
315 void KMAcctLocal::setLocation(
const TQString& aLocation)
317 mLocation = aLocation;
320 void KMAcctLocal::setProcmailLockFileName(
const TQString& s)
322 mProcmailLockFileName = s;
void setStatus(const KMMsgStatus status, int idx=-1)
Set status and mark dirty.
TQCString asString() const
Return the entire message contents as a string.
void setComplete(bool v)
Set if the message is a complete message.
TQString headerField(const TQCString &name) const
Returns the value of a header field with the given name.
The account manager is responsible for creating accounts of various types via the factory method crea...