6#include "accountmanager.h" 
    8#include "globalsettings.h" 
    9#include "kmacctfolder.h" 
   10#include "kmfoldermgr.h" 
   11#include "kmfiltermgr.h" 
   12#include "messagesender.h" 
   14#include "broadcaststatus.h" 
   15using KPIM::BroadcastStatus;
 
   16#include "kmfoldercachedimap.h" 
   18#include "progressmanager.h" 
   19using KPIM::ProgressItem;
 
   20using KPIM::ProgressManager;
 
   22#include <libkpimidentities/identitymanager.h> 
   23#include <libkpimidentities/identity.h> 
   25using KMail::FolderJob;
 
   27#include <tdeapplication.h> 
   29#include <tdemessagebox.h> 
   33#include <tqeventloop.h> 
   42#include "kmaccount.moc" 
   45KMPrecommand::KMPrecommand(
const TQString &precommand, TQObject *parent)
 
   46  : TQObject(parent), mPrecommand(precommand)
 
   48  BroadcastStatus::instance()->setStatusMsg(
 
   49      i18n(
"Executing precommand %1").arg(precommand ));
 
   51  mPrecommandProcess.setUseShell(
true);
 
   52  mPrecommandProcess << precommand;
 
   54  connect(&mPrecommandProcess, TQ_SIGNAL(processExited(TDEProcess *)),
 
   55          TQ_SLOT(precommandExited(TDEProcess *)));
 
   59KMPrecommand::~KMPrecommand()
 
   65bool KMPrecommand::start()
 
   67  bool ok = mPrecommandProcess.start( TDEProcess::NotifyOnExit );
 
   68  if (!ok) KMessageBox::error(0, i18n(
"Could not execute precommand '%1'.")
 
   75void KMPrecommand::precommandExited(TDEProcess *p)
 
   77  int exitCode = p->normalExit() ? p->exitStatus() : -1;
 
   79    KMessageBox::error(0, i18n(
"The precommand exited with code %1:\n%2")
 
   80      .arg(exitCode).arg(strerror(exitCode)));
 
   81  emit finished(!exitCode);
 
   86KMAccount::KMAccount(
AccountManager* aOwner, 
const TQString& aName, uint 
id)
 
   87  : KAccount( id, aName ),
 
   88    mTrash(
KMKernel::self()->trashFolder()->idString()),
 
   95    mPrecommandSuccess(true),
 
   97    mMailCheckProgressItem(0),
 
  103void KMAccount::init() {
 
  104  mTrash = kmkernel->trashFolder()->idString();
 
  107  mNewInFolder.clear();
 
  111KMAccount::~KMAccount()
 
  113  if ( (kmkernel && !kmkernel->shuttingDown()) && mFolder ) mFolder->removeAccount(
this);
 
  114  if (mTimer) deinstallTimer();
 
  119void KMAccount::setName(
const TQString& aName)
 
  126void KMAccount::clearPasswd()
 
  132void KMAccount::setFolder(
KMFolder* aFolder, 
bool addAccount)
 
  140  if (addAccount) mFolder->addAccount(
this);
 
  145void KMAccount::readConfig(TDEConfig& config)
 
  149  folderName = config.readEntry(
"Folder");
 
  150  setCheckInterval(config.readNumEntry(
"check-interval", 0));
 
  151  setTrash(config.readEntry(
"trash", kmkernel->trashFolder()->idString()));
 
  152  setCheckExclude(config.readBoolEntry(
"check-exclude", 
false));
 
  153  setPrecommand(config.readPathEntry(
"precommand"));
 
  154  setIdentityId(config.readNumEntry(
"identity-id", 0));
 
  155  if (!folderName.isEmpty())
 
  157    setFolder(kmkernel->folderMgr()->findIdString(folderName), 
true);
 
  166void KMAccount::readTimerConfig()
 
  178void KMAccount::writeConfig(TDEConfig& config)
 
  181  KAccount::writeConfig(config);
 
  183  config.writeEntry(
"Type", type());
 
  184  config.writeEntry(
"Folder", mFolder ? mFolder->idString() : TQString());
 
  185  config.writeEntry(
"check-interval", mInterval);
 
  186  config.writeEntry(
"check-exclude", mExclude);
 
  187  config.writePathEntry(
"precommand", mPrecommand);
 
  188  config.writeEntry(
"trash", mTrash);
 
  189  if ( mIdentityId && mIdentityId != kmkernel->identityManager()->defaultIdentity().uoid() )
 
  190    config.writeEntry(
"identity-id", mIdentityId);
 
  192    config.deleteEntry(
"identity-id");
 
  197void KMAccount::sendReceipt(
KMMessage* aMsg)
 
  199  TDEConfig* cfg = KMKernel::config();
 
  202  TDEConfigGroupSaver saver(cfg, 
"General");
 
  204  sendReceipts = cfg->readBoolEntry(
"send-receipts", 
false);
 
  205  if (!sendReceipts) 
return;
 
  209    mReceipts.append(newMsg);
 
  210    TQTimer::singleShot( 0, 
this, TQ_SLOT( sendReceipts() ) );
 
  216bool KMAccount::processNewMsg(
KMMessage* aMsg)
 
  218  int rc, processResult;
 
  223  KMFolderCachedImap* parent = 0;
 
  224  if( type() == 
"cachedimap" )
 
  225    parent = 
static_cast<KMFolderCachedImap*
>( aMsg->storage() );
 
  234  if ( type() != 
"cachedimap" && type() != 
"imap" ) {
 
  251  processResult = kmkernel->filterMgr()->process(aMsg,KMFilterMgr::Inbound,
true,
id());
 
  252  if (processResult == 2) {
 
  253    perror(
"Critical error: Unable to collect mail (out of space?)");
 
  254    KMessageBox::information(0,(i18n(
"Critical error: " 
  255      "Unable to collect mail: ")) + TQString::fromLocal8Bit(strerror(errno)));
 
  258  else if (processResult == 1)
 
  260    if( type() == 
"cachedimap" )
 
  265      kmkernel->filterMgr()->tempOpenFolder(mFolder);
 
  266      rc = mFolder->addMsg(aMsg);
 
  276        perror(
"failed to add message");
 
  277        KMessageBox::information(0, i18n(
"Failed to add message:\n") +
 
  278                                 TQString(strerror(rc)));
 
  281      int count = mFolder->count();
 
  283      if (count != 1) mFolder->unGetMsg(count - 1);
 
  289  if ( processResult == 1 ) {
 
  290    folderId = ( type() == 
"cachedimap" ) ? parent->folder()->idString()
 
  291                                          : mFolder->idString();
 
  294    folderId = aMsg->parent()->idString();
 
  296  addToNewInFolder( folderId, 1 );
 
  302void KMAccount::setCheckInterval(
int aInterval)
 
  307    mInterval = aInterval;
 
  311int KMAccount::checkInterval()
 const 
  313  if ( mInterval <= 0 )
 
  315  return TQMAX( mInterval, GlobalSettings::self()->minimumCheckInterval() );
 
  319void KMAccount::deleteFolderJobs()
 
  321  mJobList.setAutoDelete(
true);
 
  323  mJobList.setAutoDelete(
false);
 
  327void KMAccount::ignoreJobsForMessage( 
KMMessage* msg )
 
  330  for( TQPtrListIterator<FolderJob> it(mJobList); it.current(); ++it ) {
 
  331    if ( it.current()->msgList().first() == msg) {
 
  332      FolderJob *job = it.current();
 
  333      mJobList.remove( job );
 
  341void KMAccount::setCheckExclude(
bool aExclude)
 
  348void KMAccount::installTimer()
 
  350  if (mInterval <= 0) 
return;
 
  353    mTimer = 
new TQTimer(0, 
"mTimer");
 
  354    connect(mTimer,TQ_SIGNAL(timeout()),TQ_SLOT(mailCheck()));
 
  360  mTimer->start( checkInterval() * 60000 );
 
  365void KMAccount::deinstallTimer()
 
  372bool KMAccount::runPrecommand(
const TQString &precommand)
 
  375  if ( precommand.isEmpty() )
 
  378  KMPrecommand precommandProcess(precommand, 
this);
 
  380  BroadcastStatus::instance()->setStatusMsg(
 
  381      i18n(
"Executing precommand %1").arg(precommand ));
 
  383  connect(&precommandProcess, TQ_SIGNAL(finished(
bool)),
 
  384          TQ_SLOT(precommandExited(
bool)));
 
  386  kdDebug(5006) << 
"Running precommand " << precommand << endl;
 
  387  if (!precommandProcess.start()) 
return false;
 
  389  tdeApp->eventLoop()->enterLoop();
 
  391  return mPrecommandSuccess;
 
  395void KMAccount::precommandExited(
bool success)
 
  397  mPrecommandSuccess = success;
 
  398  tdeApp->eventLoop()->exitLoop();
 
  402void KMAccount::mailCheck()
 
  410      acctmgr->singleCheckMail(
this, 
false);
 
  415void KMAccount::sendReceipts()
 
  417  TQValueList<KMMessage*>::Iterator it;
 
  418  for(it = mReceipts.begin(); it != mReceipts.end(); ++it)
 
  419    kmkernel->msgSender()->send(*it); 
 
  424TQString KMAccount::encryptStr(
const TQString &aStr)
 
  427  for (uint i = 0; i < aStr.length(); i++)
 
  430    result += (aStr[i].unicode() <= 0x21 ) ? aStr[i] :
 
  431      TQChar(0x1001F - aStr[i].unicode());
 
  436TQString KMAccount::importPassword(
const TQString &aStr)
 
  439  unsigned int len = aStr.length();
 
  441  result.resize(len+1);
 
  443  for (i=0; i<len; i++)
 
  446    val = (255-
' ') - val;
 
  447    result[i] = (char)(val + 
' ');
 
  451  return encryptStr(result);
 
  454void KMAccount::invalidateIMAPFolders()
 
  459void KMAccount::pseudoAssign( 
const KMAccount * a ) {
 
  462  setName( a->name() );
 
  464  setCheckInterval( a->checkInterval() );
 
  465  setCheckExclude( a->checkExclude() );
 
  466  setFolder( a->folder() );
 
  467  setPrecommand( a->precommand() );
 
  468  setTrash( a->trash() );
 
  469  setIdentityId( a->identityId() );
 
  473void KMAccount::checkDone( 
bool newmail, CheckStatus status )
 
  475    setCheckingMail( 
false );
 
  479    mTimer->start( checkInterval() * 60000 );
 
  480  if ( mMailCheckProgressItem ) {
 
  483    ProgressItem *savedMailCheckProgressItem = mMailCheckProgressItem;
 
  484    mMailCheckProgressItem = 0;
 
  485    savedMailCheckProgressItem->setComplete(); 
 
  488  emit newMailsProcessed( mNewInFolder );
 
  489  emit finishedCheck( newmail, status );
 
  490  mNewInFolder.clear();
 
  494void KMAccount::addToNewInFolder( TQString folderId, 
int num )
 
  496  if ( mNewInFolder.find( folderId ) == mNewInFolder.end() )
 
  497    mNewInFolder[folderId] = num;
 
  499    mNewInFolder[folderId] += num;
 
Simple wrapper class that contains the kmail account handling stuff that is usually not required outs...
 
Central point of coordination in KMail.
 
void setStatus(const KMMsgStatus status, int idx=-1)
Set status and mark dirty.
 
KMMessage * createDeliveryReceipt() const
Create a new message that is a delivery receipt of this message, filling required header fileds with ...
 
The account manager is responsible for creating accounts of various types via the factory method crea...