7 #include <tqfileinfo.h>
8 #include "kmacctmaildir.h"
9 #include "kmfoldermaildir.h"
10 #include "kmacctfolder.h"
11 #include "broadcaststatus.h"
12 using KPIM::BroadcastStatus;
13 #include "progressmanager.h"
14 using KPIM::ProgressManager;
16 #include <tdeapplication.h>
17 #include <tdelocale.h>
18 #include <tdemessagebox.h>
20 #include <tdeconfig.h>
22 #include <tqstylesheet.h>
36 KMAcctMaildir::KMAcctMaildir(
AccountManager* aOwner,
const TQString& aAccountName, uint
id):
37 KMAccount(aOwner, aAccountName, id)
43 KMAcctMaildir::~KMAcctMaildir()
50 TQString KMAcctMaildir::type(
void)
const
57 void KMAcctMaildir::init() {
60 mLocation = getenv(
"MAIL");
61 if (mLocation.isNull()) {
62 mLocation = getenv(
"HOME");
63 mLocation +=
"/Maildir/";
69 void KMAcctMaildir::pseudoAssign(
const KMAccount * a )
71 KMAccount::pseudoAssign( a );
73 const KMAcctMaildir * m =
dynamic_cast<const KMAcctMaildir*
>( a );
76 setLocation( m->location() );
80 void KMAcctMaildir::processNewMail(
bool)
85 if ( precommand().isEmpty() ) {
86 TQFileInfo fi( location() );
88 checkDone( hasNewMail, CheckOK );
89 BroadcastStatus::instance()->setStatusMsgTransmissionCompleted( mName, 0 );
94 KMFolder mailFolder(0, location(), KMFolderTypeMaildir,
104 checkDone( hasNewMail, CheckError );
105 BroadcastStatus::instance()->setStatusMsg( i18n(
"Transmission failed." ));
109 BroadcastStatus::instance()->setStatusMsg(
110 i18n(
"Preparing transmission from \"%1\"...").arg(mName));
112 Q_ASSERT( !mMailCheckProgressItem );
113 TQString escapedName = TQStyleSheet::escape( mName );
114 mMailCheckProgressItem = KPIM::ProgressManager::createProgressItem(
117 i18n(
"Preparing transmission from \"%1\"...").arg( escapedName ),
122 if (!runPrecommand(precommand()))
124 kdDebug(5006) <<
"cannot run precommand " << precommand() << endl;
125 checkDone( hasNewMail, CheckError );
126 BroadcastStatus::instance()->setStatusMsg( i18n(
"Transmission failed." ));
130 rc = mailFolder.open(
"acctmaildirMail");
133 TQString aStr = i18n(
"<qt>Cannot open folder <b>%1</b>.</qt>").arg( mailFolder.location() );
134 KMessageBox::sorry(0, aStr);
135 kdDebug(5006) <<
"cannot open folder " << mailFolder.location() << endl;
136 checkDone( hasNewMail, CheckError );
137 BroadcastStatus::instance()->setStatusMsg( i18n(
"Transmission failed." ));
141 mFolder->open(
"acctmaildirFold");
144 num = mailFolder.count();
150 TQString statusMsgStub = i18n(
"Moving message %3 of %2 from %1.")
151 .arg(mailFolder.location()).arg(num);
153 mMailCheckProgressItem->setTotalItems( num );
155 for (i=0; i<num; i++)
158 if( kmkernel->mailCheckAborted() ) {
159 BroadcastStatus::instance()->setStatusMsg( i18n(
"Transmission aborted.") );
165 TQString statusMsg = statusMsgStub.arg(i);
166 mMailCheckProgressItem->incCompletedItems();
167 mMailCheckProgressItem->updateProgress();
168 mMailCheckProgressItem->setStatus( statusMsg );
170 msg = mailFolder.take(0);
175 msg->setEncryptionStateChar( msg->
headerField(
"X-KMail-EncryptionState" ).at(0));
176 msg->setSignatureStateChar( msg->
headerField(
"X-KMail-SignatureState" ).at(0));
178 addedOk = processNewMsg(msg);
183 if (t.elapsed() >= 200) {
184 kapp->processEvents();
190 if( mMailCheckProgressItem ) {
191 BroadcastStatus::instance()->setStatusMsgTransmissionCompleted( num );
192 mMailCheckProgressItem->setStatus(
193 i18n(
"Fetched 1 message from maildir folder %1.",
194 "Fetched %n messages from maildir folder %1.",
195 num ).arg(mailFolder.location() ) );
197 mMailCheckProgressItem->setComplete();
198 mMailCheckProgressItem = 0;
202 BroadcastStatus::instance()->setStatusMsgTransmissionCompleted( mName, num );
206 mailFolder.close(
"acctmaildirMail");
207 mFolder->close(
"acctmaildirFold");
209 checkDone( hasNewMail, CheckOK );
216 void KMAcctMaildir::readConfig(TDEConfig& config)
218 KMAccount::readConfig(config);
219 mLocation = config.readPathEntry(
"Location", mLocation);
224 void KMAcctMaildir::writeConfig(TDEConfig& config)
226 KMAccount::writeConfig(config);
227 config.writePathEntry(
"Location", mLocation);
231 void KMAcctMaildir::setLocation(
const TQString& aLocation)
233 mLocation = aLocation;
void setStatus(const KMMsgStatus status, int idx=-1)
Set status and mark dirty.
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...