fix errors found while translating
[kdepim.git] / kmail / kmacctmaildir.cpp
blob9ea9ddf48654910182686b718a17d9b225b4d9cc
1 // kmacctmaildir.cpp
2 #include "kmacctmaildir.h"
3 #include <config-kmail.h>
4 #include "kmfoldermaildir.h"
5 #include "kmacctfolder.h"
6 #include "broadcaststatus.h"
7 using KPIM::BroadcastStatus;
8 #include "progressmanager.h"
9 using KPIM::ProgressManager;
11 #include <klocale.h>
12 #include <kmessagebox.h>
13 #include <kdebug.h>
14 #include <kconfiggroup.h>
16 #include <QFileInfo>
17 #include <QTime>
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <errno.h>
22 #include <assert.h>
24 #ifdef HAVE_PATHS_H
25 #include <paths.h> /* defines _PATH_MAILDIR */
26 #endif
28 #undef None
30 //-----------------------------------------------------------------------------
31 KMAcctMaildir::KMAcctMaildir(AccountManager* aOwner, const QString& aAccountName, uint id):
32 KMAccount(aOwner, aAccountName, id)
37 //-----------------------------------------------------------------------------
38 KMAcctMaildir::~KMAcctMaildir()
40 mLocation = "";
44 //-----------------------------------------------------------------------------
45 void KMAcctMaildir::init() {
46 KMAccount::init();
48 mLocation = qgetenv("MAIL");
49 if (mLocation.isNull()) {
50 mLocation = qgetenv("HOME");
51 mLocation += "/Maildir/";
56 //-----------------------------------------------------------------------------
57 void KMAcctMaildir::pseudoAssign( const KMAccount * a )
59 KMAccount::pseudoAssign( a );
61 const KMAcctMaildir * m = dynamic_cast<const KMAcctMaildir*>( a );
62 if ( !m ) return;
64 setLocation( m->location() );
67 //-----------------------------------------------------------------------------
68 void KMAcctMaildir::processNewMail(bool)
70 QTime t;
71 hasNewMail = false;
73 if ( precommand().isEmpty() ) {
74 QFileInfo fi( location() );
75 if ( !fi.exists() ) {
76 checkDone( hasNewMail, CheckOK );
77 BroadcastStatus::instance()->setStatusMsgTransmissionCompleted( mName, 0 );
78 return;
82 KMFolder mailFolder(0, location(), KMFolderTypeMaildir,
83 false /* no index */, false /* don't export sernums */);
85 long num = 0;
86 int rc;
87 KMMessage* msg;
88 bool addedOk;
90 if (!mFolder) {
91 checkDone( hasNewMail, CheckError );
92 BroadcastStatus::instance()->setStatusMsg( i18n( "Transmission failed." ));
93 return;
96 BroadcastStatus::instance()->setStatusMsg(
97 i18n("Preparing transmission from \"%1\"...", mName));
99 Q_ASSERT( !mMailCheckProgressItem );
100 mMailCheckProgressItem = KPIM::ProgressManager::createProgressItem(
101 "MailCheck" + mName,
102 mName,
103 i18n("Preparing transmission from \"%1\"...", mName),
104 false, // cannot be canceled
105 false ); // no tls/ssl
107 // run the precommand
108 if (!runPrecommand(precommand()))
110 kDebug(5006) <<"cannot run precommand" << precommand();
111 checkDone( hasNewMail, CheckError );
112 BroadcastStatus::instance()->setStatusMsg( i18n( "Transmission failed." ));
113 return;
116 rc = mailFolder.open( "acctmaildirMail" );
117 if (rc)
119 QString aStr = i18n("<qt>Cannot open folder <b>%1</b>.</qt>", mailFolder.location() );
120 KMessageBox::sorry(0, aStr);
121 kDebug(5006) <<"cannot open folder" << mailFolder.location();
122 checkDone( hasNewMail, CheckError );
123 BroadcastStatus::instance()->setStatusMsg( i18n( "Transmission failed." ));
124 return;
127 mFolder->open( "acctmaildirFold" );
130 num = mailFolder.count();
132 addedOk = true;
133 t.start();
135 mMailCheckProgressItem->setTotalItems( num );
137 for (long i=0; i<num; i++)
140 if( kmkernel->mailCheckAborted() ) {
141 BroadcastStatus::instance()->setStatusMsg( i18n("Transmission aborted.") );
142 num = i;
143 addedOk = false;
145 if (!addedOk) break;
147 QString statusMsg = i18n( "Moving message %1 of %2 from %3.",
148 i, num, mailFolder.location() );
149 mMailCheckProgressItem->incCompletedItems();
150 mMailCheckProgressItem->updateProgress();
151 mMailCheckProgressItem->setStatus( statusMsg );
153 msg = mailFolder.take(0);
154 if (msg)
156 msg->setStatus(msg->headerField("Status").toLatin1(),
157 msg->headerField("X-Status").toLatin1());
158 if ( !msg->headerField( "X-KMail-EncryptionState" ).isEmpty() )
159 msg->setEncryptionStateChar( msg->headerField( "X-KMail-EncryptionState" ).at(0) );
160 if ( !msg->headerField( "X-KMail-SignatureState" ).isEmpty() )
161 msg->setSignatureStateChar( msg->headerField( "X-KMail-SignatureState" ).at(0));
163 addedOk = processNewMsg(msg);
164 if (addedOk)
165 hasNewMail = true;
168 if (t.elapsed() >= 200) { //hardwired constant
169 qApp->processEvents();
170 t.start();
175 if( mMailCheckProgressItem ) { // do this only once...
176 BroadcastStatus::instance()->setStatusMsgTransmissionCompleted( num );
177 mMailCheckProgressItem->setStatus(
178 i18np( "Fetched 1 message from maildir folder %2.",
179 "Fetched %1 messages from maildir folder %2.",
180 num, mailFolder.location() ) );
182 mMailCheckProgressItem->setComplete();
183 mMailCheckProgressItem = 0;
185 if (addedOk)
187 BroadcastStatus::instance()->setStatusMsgTransmissionCompleted( mName, num );
189 // else warning is written already
191 mailFolder.close( "acctmaildirMail" );
192 mFolder->close( "acctmaildirFold" );
194 checkDone( hasNewMail, CheckOK );
196 return;
200 //-----------------------------------------------------------------------------
201 void KMAcctMaildir::readConfig(KConfigGroup& config)
203 KMAccount::readConfig(config);
204 mLocation = config.readPathEntry("Location", mLocation);
208 //-----------------------------------------------------------------------------
209 void KMAcctMaildir::writeConfig(KConfigGroup& config)
211 KMAccount::writeConfig(config);
212 config.writePathEntry("Location", mLocation);
215 //-----------------------------------------------------------------------------
216 void KMAcctMaildir::setLocation(const QString& aLocation)
218 mLocation = aLocation;