9 #include <weaverlogger.h>
11 #include "globalsettings.h"
12 #include "broadcaststatus.h"
13 using KPIM::BroadcastStatus;
14 #include "kmstartup.h"
16 #include "kmmainwin.h"
18 #include "kmmsgpart.h"
19 #include "kmreadermainwin.h"
20 #include "kmfoldermgr.h"
21 #include "kmfoldercachedimap.h"
22 #include "kmacctcachedimap.h"
23 #include "kmfiltermgr.h"
24 #include "kmfilteraction.h"
25 #include "kmheaders.h"
26 #define REALLY_WANT_KMSENDER
28 #undef REALLY_WANT_KMSENDER
29 #include "undostack.h"
30 #include "accountmanager.h"
32 #include <libtdepim/tdefileio.h>
33 #include "kmversion.h"
34 #include "kmreaderwin.h"
35 #include "kmmainwidget.h"
36 #include "kmfoldertree.h"
37 #include "recentaddresses.h"
38 using TDERecentAddress::RecentAddresses;
39 #include "kmmsgdict.h"
40 #include <libkpimidentities/identity.h>
41 #include <libkpimidentities/identitymanager.h>
42 #include "configuredialog.h"
43 #include "kmcommands.h"
44 #include "kmsystemtray.h"
45 #include "transportmanager.h"
46 #include "importarchivedialog.h"
47 #include <mimelib/enum.h>
50 #include "kmailicalifaceimpl.h"
51 #include "mailserviceimpl.h"
52 using KMail::MailServiceImpl;
53 #include "mailcomposerIface.h"
54 #include "folderIface.h"
55 using KMail::FolderIface;
56 #include "jobscheduler.h"
57 #include "templateparser.h"
59 #include <tdeapplication.h>
60 #include <tdemessagebox.h>
61 #include <knotifyclient.h>
62 #include <kstaticdeleter.h>
63 #include <kstandarddirs.h>
64 #include <tdeconfig.h>
65 #include <kprogress.h>
66 #include <kpassivepopup.h>
67 #include <dcopclient.h>
68 #include <ksystemtray.h>
71 #include <tdeio/netaccess.h>
72 #include <tdewallet.h>
73 using TDEWallet::Wallet;
74 #include "actionscheduler.h"
76 #include <qutf7codec.h>
79 #include <tqwidgetlist.h>
80 #include <tqobjectlist.h>
82 #include <sys/types.h>
92 #include <tdecmdlineargs.h>
93 #include <tdestartupinfo.h>
96 static bool s_askingToGoOnline =
false;
101 KMKernel::KMKernel (TQObject *parent,
const char *name) :
102 DCOPObject(
"KMailIface"), TQObject(parent, name),
103 mIdentityManager(0), mConfigureDialog(0),
104 mContextMenuShown( false ), mWallet( 0 )
106 kdDebug(5006) <<
"KMKernel::KMKernel" << endl;
108 the_startingUp =
true;
109 closed_by_user =
true;
110 the_firstInstance =
true;
114 the_outboxFolder = 0;
117 the_draftsFolder = 0;
118 the_templatesFolder = 0;
121 the_imapFolderMgr = 0;
122 the_dimapFolderMgr = 0;
123 the_searchFolderMgr = 0;
127 the_popFilterMgr = 0;
128 the_filterActionDict = 0;
131 mMailCheckAborted =
false;
138 GlobalSettings::self();
151 if ( !TQTextCodec::codecForName(
"utf-7") ) {
152 kdDebug(5006) <<
"No TQt-native utf-7 codec found; registering TQUtf7Codec from libtdenetwork" << endl;
153 (void)
new TQUtf7Codec();
159 if ( TQCString(TQTextCodec::codecForLocale()->name()).lower() ==
"eucjp" )
161 netCodec = TQTextCodec::codecForName(
"jis7");
166 netCodec = TQTextCodec::codecForLocale();
168 mMailService =
new MailServiceImpl();
170 connectDCOPSignal( 0, 0,
"kmailSelectFolder(TQString)",
171 "selectFolder(TQString)",
false );
173 #ifdef __TDE_HAVE_TDEHWLIB
174 mNetworkManager = TDEGlobal::networkManager();
175 if (mNetworkManager) {
176 connect( mNetworkManager, TQ_SIGNAL( networkDeviceStateChanged( TDENetworkConnectionStatus::TDENetworkConnectionStatus, TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString ) ),
177 this, TQ_SLOT( slotNetworkStateChanged( TDENetworkConnectionStatus::TDENetworkConnectionStatus, TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString ) ) );
178 if (networkStateConnected()) {
188 KMKernel::~KMKernel ()
190 TQMap<TDEIO::Job*, putData>::Iterator it = mPutJobs.begin();
191 while ( it != mPutJobs.end() )
193 TDEIO::Job *job = it.key();
194 mPutJobs.remove( it );
196 it = mPutJobs.begin();
204 GlobalSettings::self()->writeConfig();
208 kdDebug(5006) <<
"KMKernel::~KMKernel" << endl;
213 TQString to, cc, bcc, subj, body;
214 QCStringList customHeaders;
216 KURL::List attachURLs;
219 bool viewOnly =
false;
220 bool calledWithSession =
false;
223 TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
224 if (!args->getOption(
"subject").isNull())
226 subj = TQString::fromLocal8Bit(args->getOption(
"subject"));
234 if ( subj ==
"ession" ) {
236 calledWithSession =
true;
242 if (!args->getOption(
"cc").isNull())
245 cc = TQString::fromLocal8Bit(args->getOption(
"cc"));
248 if (!args->getOption(
"bcc").isNull())
251 bcc = TQString::fromLocal8Bit(args->getOption(
"bcc"));
254 if (!args->getOption(
"msg").isNull())
257 messageFile.setPath( TQString::fromLocal8Bit(args->getOption(
"msg")) );
260 if (!args->getOption(
"body").isNull())
263 body = TQString::fromLocal8Bit(args->getOption(
"body"));
266 QCStringList attachList = args->getOptionList(
"attach");
267 if (!attachList.isEmpty())
270 for ( QCStringList::Iterator it = attachList.begin() ; it != attachList.end() ; ++it )
271 if ( !(*it).isEmpty() )
272 attachURLs += KURL( TQString::fromLocal8Bit( *it ) );
275 customHeaders = args->getOptionList(
"header");
277 if (args->isSet(
"composer"))
280 if (args->isSet(
"check"))
283 if ( !args->getOption(
"view" ).isNull() ) {
285 const TQString filename =
286 TQString::fromLocal8Bit( args->getOption(
"view" ) );
287 messageFile = KURL::fromPathOrURL( filename );
288 if ( !messageFile.isValid() ) {
289 messageFile = KURL();
290 messageFile.setPath( filename );
294 if ( !calledWithSession ) {
297 for(
int i= 0; i < args->count(); i++)
299 if (strncasecmp(args->arg(i),
"mailto:",7)==0)
300 to += args->url(i).path() +
", ";
302 TQString tmpArg = TQString::fromLocal8Bit( args->arg(i) );
311 if ( !to.isEmpty() ) {
313 to.truncate( to.length() - 2 );
317 if ( !calledWithSession )
320 if ( !noArgsOpensReader && !mailto && !
checkMail && !viewOnly )
324 viewMessage( messageFile );
326 action( mailto,
checkMail, to, cc, bcc, subj, body, messageFile,
327 attachURLs, customHeaders );
336 if ( !kmkernel->askToGoOnline() )
338 kmkernel->acctMgr()->checkMail(
false);
341 TQStringList KMKernel::accounts()
343 if( kmkernel->acctMgr() )
344 return kmkernel->acctMgr()->getAccounts();
345 return TQStringList();
348 void KMKernel::checkAccount (
const TQString &account)
350 kdDebug(5006) <<
"KMKernel::checkMail called" << endl;
352 KMAccount* acct = kmkernel->acctMgr()->findByName(account);
354 kmkernel->acctMgr()->singleCheckMail(acct,
false);
357 void KMKernel::loadProfile(
const TQString& )
361 void KMKernel::saveToProfile(
const TQString& )
const
365 void KMKernel::openReader(
bool onlyCheck )
368 TDEMainWindow *ktmw = 0;
369 kdDebug(5006) <<
"KMKernel::openReader called" << endl;
371 if (TDEMainWindow::memberList)
372 for (ktmw = TDEMainWindow::memberList->first(); ktmw;
373 ktmw = TDEMainWindow::memberList->next())
374 if (ktmw->isA(
"KMMainWin"))
379 mWin = (KMMainWin *) ktmw;
380 activate = !onlyCheck;
384 mWin =
new KMMainWin;
392 #if defined TQ_WS_X11 && ! defined K_WS_TQTONLY
393 TDEStartupInfo::setNewStartupId( mWin, kapp->startupId() );
399 const TQString &bcc,
const TQString &subject,
400 const TQString &body,
int hidden,
401 const KURL &messageFile,
402 const KURL::List &attachURLs,
403 const QCStringList &customHeaders)
405 kdDebug(5006) <<
"KMKernel::openComposer called" << endl;
412 msg->setTo( KMMsgBase::decodeRFC2047String( to.latin1() ) );
414 msg->setCc( KMMsgBase::decodeRFC2047String( cc.latin1() ) );
416 msg->setBcc( KMMsgBase::decodeRFC2047String( bcc.latin1() ) );
417 if (!subject.isEmpty()) msg->setSubject(subject);
418 if (!messageFile.isEmpty() && messageFile.isLocalFile()) {
419 TQCString str = KPIM::kFileToString( messageFile.path(),
true,
false );
420 if( !str.isEmpty() ) {
421 msg->
setBody( TQString(TQString::fromLocal8Bit( str )).utf8() );
424 parser.process( NULL, NULL );
427 else if (!body.isEmpty())
434 parser.process( NULL, NULL );
437 if (!customHeaders.isEmpty())
439 for ( QCStringList::ConstIterator it = customHeaders.begin() ; it != customHeaders.end() ; ++it )
440 if ( !(*it).isEmpty() )
442 const int pos = (*it).find(
':' );
445 TQCString header, value;
446 header = (*it).left( pos ).stripWhiteSpace();
447 value = (*it).mid( pos+1 ).stripWhiteSpace();
448 if ( !header.isEmpty() && !value.isEmpty() )
454 KMail::Composer * cWin = KMail::makeComposer( msg );
455 cWin->setCharset(
"",
true);
456 for ( KURL::List::ConstIterator it = attachURLs.begin() ; it != attachURLs.end() ; ++it )
457 cWin->addAttach((*it));
462 #if defined TQ_WS_X11 && ! defined K_WS_TQTONLY
463 TDEStartupInfo::setNewStartupId( cWin, kapp->startupId() );
471 const TQString &bcc,
const TQString &subject,
472 const TQString &body,
int hidden,
473 const TQString &attachName,
474 const TQCString &attachCte,
475 const TQCString &attachData,
476 const TQCString &attachType,
477 const TQCString &attachSubType,
478 const TQCString &attachParamAttr,
479 const TQString &attachParamValue,
480 const TQCString &attachContDisp )
482 kdDebug(5006) <<
"KMKernel::openComposer called (deprecated version)" << endl;
484 return openComposer ( to, cc, bcc, subject, body, hidden,
485 attachName, attachCte, attachData,
486 attachType, attachSubType, attachParamAttr,
487 attachParamValue, attachContDisp, TQCString() );
491 const TQString &bcc,
const TQString &subject,
492 const TQString &body,
int hidden,
493 const TQString &attachName,
494 const TQCString &attachCte,
495 const TQCString &attachData,
496 const TQCString &attachType,
497 const TQCString &attachSubType,
498 const TQCString &attachParamAttr,
499 const TQString &attachParamValue,
500 const TQCString &attachContDisp,
501 const TQCString &attachCharset )
503 kdDebug(5006) <<
"KMKernel::openComposer called (deprecated version)" << endl;
504 return openComposer ( to, cc, bcc, subject, body, hidden,
505 attachName, attachCte, attachData,
506 attachType, attachSubType, attachParamAttr,
507 attachParamValue, attachContDisp, attachCharset, 0 );
511 const TQString &bcc,
const TQString &subject,
512 const TQString &body,
int hidden,
513 const TQString &attachName,
514 const TQCString &attachCte,
515 const TQCString &attachData,
516 const TQCString &attachType,
517 const TQCString &attachSubType,
518 const TQCString &attachParamAttr,
519 const TQString &attachParamValue,
520 const TQCString &attachContDisp,
521 const TQCString &attachCharset,
522 unsigned int identity )
524 kdDebug(5006) <<
"KMKernel::openComposer()" << endl;
527 KMMessagePart *msgPart = 0;
530 if ( !cc.isEmpty() ) msg->setCc(cc);
531 if ( !bcc.isEmpty() ) msg->setBcc(bcc);
532 if ( !subject.isEmpty() ) msg->setSubject(subject);
533 if ( !to.isEmpty() ) msg->setTo(to);
534 if ( identity > 0 ) msg->
setHeaderField(
"X-KMail-Identity", TQString::number( identity ) );
535 if ( !body.isEmpty() ) {
539 parser.process( NULL, NULL );
542 bool iCalAutoSend =
false;
543 bool noWordWrap =
false;
544 bool isICalInvitation =
false;
545 TDEConfigGroup options( config(),
"Groupware" );
546 if ( !attachData.isEmpty() ) {
547 isICalInvitation = attachName ==
"cal.ics" &&
548 attachType ==
"text" &&
549 attachSubType ==
"calendar" &&
550 attachParamAttr ==
"method";
552 if ( isICalInvitation && bcc.isEmpty() )
554 if ( isICalInvitation &&
555 GlobalSettings::self()->legacyBodyInvites() ) {
559 TQString(
"text/calendar; method=%1; "
560 "charset=\"utf-8\"" ).
561 arg( attachParamValue ) );
567 msgPart =
new KMMessagePart;
568 msgPart->setName( attachName );
569 msgPart->setCteStr( attachCte );
570 msgPart->setBodyEncoded( attachData );
571 msgPart->setTypeStr( attachType );
572 msgPart->setSubtypeStr( attachSubType );
573 msgPart->setParameter( attachParamAttr, attachParamValue );
574 if( ! GlobalSettings::self()->exchangeCompatibleInvitations() ) {
575 msgPart->setContentDisposition( attachContDisp );
577 if( !attachCharset.isEmpty() && (msgPart->type() == DwMime::kTypeText) ) {
580 msgPart->setCharset( attachCharset );
583 TDEConfigGroup options( config(),
"Groupware" );
584 iCalAutoSend = options.readBoolEntry(
"AutomaticSending",
true );
588 KMail::Composer * cWin = KMail::makeComposer();
589 cWin->setMsg( msg, !isICalInvitation );
590 cWin->setSigningAndEncryptionDisabled( isICalInvitation
591 && GlobalSettings::self()->legacyBodyInvites() );
592 cWin->setAutoDelete(
true );
594 cWin->disableWordWrap();
596 cWin->setCharset(
"",
true );
598 cWin->addAttach(msgPart);
600 if ( isICalInvitation ) {
601 cWin->disableRecipientNumberCheck();
602 cWin->disableForgottenAttachmentsCheck();
605 if ( hidden == 0 && !iCalAutoSend ) {
609 #if defined TQ_WS_X11 && ! defined K_WS_TQTONLY
610 TDEStartupInfo::setNewStartupId( cWin, kapp->startupId() );
613 cWin->setAutoDeleteWindow(
true );
623 TQStringList::const_iterator it = availTransports.find( transport );
624 if ( it == availTransports.end() ) {
625 kdWarning() <<
"The transport you entered is not available" << endl;
628 GlobalSettings::self()->setDefaultTransport( transport );
632 const TQString &bcc,
const TQString &subject,
633 const TQString &body,
bool hidden)
638 if (!cc.isEmpty()) msg->setCc(cc);
639 if (!bcc.isEmpty()) msg->setBcc(bcc);
640 if (!subject.isEmpty()) msg->setSubject(subject);
641 if (!to.isEmpty()) msg->setTo(to);
642 if (!body.isEmpty()) {
646 parser.process( NULL, NULL );
649 KMail::Composer * cWin = KMail::makeComposer( msg );
650 cWin->setCharset(
"",
true);
655 #if defined TQ_WS_X11 && ! defined K_WS_TQTONLY
656 TDEStartupInfo::setNewStartupId( cWin, kapp->startupId() );
660 return DCOPRef( cWin->asMailComposerIFace() );
669 const KURL &attachURL)
671 KMail::Composer * win = 0;
678 folder = currentFolder();
679 id = folder ? folder->identity() : 0;
686 if (!to.isEmpty()) msg->setTo(to);
687 if (!cc.isEmpty()) msg->setCc(cc);
688 if (!bcc.isEmpty()) msg->setBcc(bcc);
692 parser.process( NULL, folder );
693 win = makeComposer( msg,
id );
696 parser.process( NULL, folder );
697 win = makeComposer( msg );
701 if(!attachURL.isEmpty() && attachURL.isValid()) {
702 win->addAttach(attachURL);
709 return DCOPRef( win->asMailComposerIFace() );
712 int KMKernel::viewMessage(
const KURL & messageFile )
714 KMOpenMsgCommand *openCommand =
new KMOpenMsgCommand( 0, messageFile );
716 openCommand->start();
726 msg->setSubject( i18n(
"Certificate Signature Request" ) );
727 if (!to.isEmpty()) msg->setTo(to);
729 msg->
setBody( i18n(
"Please create a certificate from attachment and return to sender." ).utf8() );
731 KMail::Composer * cWin = KMail::makeComposer( msg );
732 cWin->setCharset(
"",
true);
733 cWin->slotSetAlwaysSend(
true );
734 if (!certData.isEmpty()) {
735 KMMessagePart *msgPart =
new KMMessagePart;
736 msgPart->setName(
"smime.p10");
737 msgPart->setCteStr(
"base64");
738 msgPart->setBodyEncodedBinary(certData);
739 msgPart->setTypeStr(
"application");
740 msgPart->setSubtypeStr(
"pkcs10");
741 msgPart->setContentDisposition(
"attachment; filename=smime.p10");
742 cWin->addAttach(msgPart);
749 KMMsgStatus KMKernel::strToStatus(
const TQString &flags)
751 KMMsgStatus status = 0;
752 if (!flags.isEmpty()) {
753 for (uint n = 0; n < flags.length() ; n++) {
756 status |= KMMsgStatusNew;
759 status |= KMMsgStatusUnread;
762 status |= KMMsgStatusOld;
765 status |= KMMsgStatusRead;
768 status |= KMMsgStatusDeleted;
771 status |= KMMsgStatusReplied;
774 status |= KMMsgStatusForwarded;
777 status |= KMMsgStatusQueued;
780 status |= KMMsgStatusTodo;
783 status |= KMMsgStatusSent;
786 status |= KMMsgStatusFlag;
789 status |= KMMsgStatusWatched;
792 status |= KMMsgStatusIgnored;
795 status |= KMMsgStatusSpam;
798 status |= KMMsgStatusHam;
801 status |= KMMsgStatusHasAttach;
804 status |= KMMsgStatusHasNoAttach;
815 const TQString & MsgStatusFlags)
817 return dcopAddMessage(foldername, KURL(msgUrlString), MsgStatusFlags);
821 const TQString & MsgStatusFlags)
823 kdDebug(5006) <<
"KMKernel::dcopAddMessage called" << endl;
825 if ( foldername.isEmpty() || foldername.startsWith(
"."))
829 bool readFolderMsgIds =
false;
830 TQString _foldername = foldername.stripWhiteSpace();
831 _foldername = _foldername.replace(
'\\',
"");
833 if ( foldername != mAddMessageLastFolder ) {
834 mAddMessageMsgIds.clear();
835 readFolderMsgIds =
true;
836 mAddMessageLastFolder = foldername;
839 if (!msgUrl.isEmpty() && msgUrl.isLocalFile()) {
848 const TQCString messageText =
849 KPIM::kFileToString( msgUrl.path(),
true,
false );
850 if ( messageText.isEmpty() )
854 msg->fromString( messageText );
856 if (readFolderMsgIds) {
857 if ( foldername.contains(
"/")) {
858 TQString tmp_fname =
"";
863 TQStringList subFList = TQStringList::split(
"/",_foldername,
false);
865 for ( TQStringList::Iterator it = subFList.begin(); it != subFList.end(); ++it ) {
866 TQString _newFolder = *it;
867 if(_newFolder.startsWith(
"."))
return -1;
870 folder = the_folderMgr->findOrCreate(*it,
false);
873 tmp_fname =
"/" + *it;
878 tmp_fname +=
"/" + *it;
879 if(!the_folderMgr->getFolderByURL( tmp_fname )) {
880 folder = the_folderMgr->createFolder(*it,
false, folder->
folderType(), subfolder);
883 if(!(folder = the_folderMgr->getFolderByURL( tmp_fname )))
return -1;
887 mAddMsgCurrentFolder = the_folderMgr->getFolderByURL( tmp_fname );
888 if(!folder)
return -1;
891 mAddMsgCurrentFolder = the_folderMgr->findOrCreate(_foldername,
false);
895 if ( mAddMsgCurrentFolder ) {
896 if (readFolderMsgIds) {
921 mAddMsgCurrentFolder->
open(
"dcopadd");
922 for( i=0; i<mAddMsgCurrentFolder->
count(); i++) {
923 KMMsgBase *mb = mAddMsgCurrentFolder->
getMsgBase(i);
924 TQString
id = mb->msgIdMD5();
925 if (
id.isEmpty() ) {
928 id = mb->fromStrip();
936 if ( !
id.isEmpty() ) {
937 mAddMessageMsgIds.append(
id);
940 mAddMsgCurrentFolder->
close(
"dcopadd");
943 TQString msgId = msg->msgIdMD5();
944 if ( msgId.isEmpty()) {
946 if ( msgId.isEmpty() )
947 msgId = msg->fromStrip();
948 if ( msgId.isEmpty() )
949 msgId = msg->toStrip();
954 int k = mAddMessageMsgIds.findIndex( msgId );
958 if ( !msgId.isEmpty() ) {
959 mAddMessageMsgIds.append( msgId );
962 if ( !MsgStatusFlags.isEmpty() ) {
963 KMMsgStatus status = strToStatus(MsgStatusFlags);
968 if ( mAddMsgCurrentFolder->
addMsg( msg, &index ) == 0 ) {
969 mAddMsgCurrentFolder->
unGetMsg( index );
991 mAddMessageMsgIds.clear();
992 mAddMessageLastFolder = TQString();
996 const TQString & msgUrlString,
997 const TQString & MsgStatusFlags)
1003 const KURL & msgUrl,
1004 const TQString & MsgStatusFlags)
1008 kdDebug(5006) <<
"KMKernel::dcopAddMessage_fastImport called" << endl;
1010 if ( foldername.isEmpty() || foldername.startsWith(
"."))
1014 bool createNewFolder =
false;
1016 TQString _foldername = foldername.stripWhiteSpace();
1017 _foldername = _foldername.replace(
'\\',
"");
1019 if ( foldername != mAddMessageLastFolder ) {
1020 createNewFolder =
true;
1021 mAddMessageLastFolder = foldername;
1025 if ( !msgUrl.isEmpty() && msgUrl.isLocalFile() ) {
1026 const TQCString messageText =
1027 KPIM::kFileToString( msgUrl.path(),
true,
false );
1028 if ( messageText.isEmpty() )
1032 msg->fromString( messageText );
1034 if (createNewFolder) {
1035 if ( foldername.contains(
"/")) {
1036 TQString tmp_fname =
"";
1041 TQStringList subFList = TQStringList::split(
"/",_foldername,
false);
1043 for ( TQStringList::Iterator it = subFList.begin(); it != subFList.end(); ++it ) {
1044 TQString _newFolder = *it;
1045 if(_newFolder.startsWith(
"."))
return -1;
1048 folder = the_folderMgr->findOrCreate(*it,
false);
1051 tmp_fname =
"/" + *it;
1056 tmp_fname +=
"/" + *it;
1057 if(!the_folderMgr->getFolderByURL( tmp_fname )) {
1058 folder = the_folderMgr->createFolder(*it,
false, folder->
folderType(), subfolder);
1060 if(!(folder = the_folderMgr->getFolderByURL( tmp_fname )))
return -1;
1064 mAddMsgCurrentFolder = the_folderMgr->getFolderByURL( tmp_fname );
1065 if(!folder)
return -1;
1068 mAddMsgCurrentFolder = the_folderMgr->findOrCreate(_foldername,
false);
1072 if ( mAddMsgCurrentFolder ) {
1075 if( !MsgStatusFlags.isEmpty() ) {
1076 KMMsgStatus status = strToStatus(MsgStatusFlags);
1080 if ( mAddMsgCurrentFolder->
addMsg( msg, &index ) == 0 ) {
1081 mAddMsgCurrentFolder->
unGetMsg( index );
1098 void KMKernel::showImportArchiveDialog()
1101 KMail::ImportArchiveDialog *importDialog =
new KMail::ImportArchiveDialog( mainWidget, WDestructiveClose );
1102 importDialog->setFolder( mainWidget->folderTree()->currentFolder() );
1103 importDialog->show();
1106 TQStringList KMKernel::folderList()
const
1108 TQStringList folders;
1109 const TQString localPrefix =
"/Local";
1110 folders << localPrefix;
1111 the_folderMgr->getFolderURLS( folders, localPrefix );
1112 the_imapFolderMgr->getFolderURLS( folders );
1113 the_dimapFolderMgr->getFolderURLS( folders );
1117 DCOPRef KMKernel::getFolder(
const TQString& vpath )
1119 const TQString localPrefix =
"/Local";
1120 if ( the_folderMgr->getFolderByURL( vpath ) )
1121 return DCOPRef(
new FolderIface( vpath ) );
1122 else if ( vpath.startsWith( localPrefix ) &&
1123 the_folderMgr->getFolderByURL( vpath.mid( localPrefix.length() ) ) )
1124 return DCOPRef(
new FolderIface( vpath.mid( localPrefix.length() ) ) );
1125 else if ( the_imapFolderMgr->getFolderByURL( vpath ) )
1126 return DCOPRef(
new FolderIface( vpath ) );
1127 else if ( the_dimapFolderMgr->getFolderByURL( vpath ) )
1128 return DCOPRef(
new FolderIface( vpath ) );
1132 void KMKernel::raise()
1134 DCOPRef kmail(
"kmail",
"kmail" );
1135 kmail.call(
"newInstance" );
1140 KMMainWidget *mainWidget = 0;
1141 if (TDEMainWindow::memberList) {
1142 TDEMainWindow *win = 0;
1146 for (win = TDEMainWindow::memberList->first(); win;
1147 win = TDEMainWindow::memberList->next()) {
1149 l = win->queryList(
"KMMainWidget");
1150 if (l && l->first()) {
1151 mainWidget =
dynamic_cast<KMMainWidget *
>(l->first());
1152 if (win->isActiveWindow())
1162 if (!folder || (idx == -1))
1165 KMMsgBase *msgBase = folder->
getMsgBase(idx);
1168 bool unGet = !msgBase->isMessage();
1171 KMReaderMainWin *win =
new KMReaderMainWin(
false,
false );
1174 newMessage->setMsgSerNum( msg->getMsgSerNum() );
1176 win->showMsg( GlobalSettings::self()->overrideCharacterEncoding(),
newMessage );
1192 if (!folder || (idx == -1))
1195 KMMsgBase *msgBase = folder->
getMsgBase(idx);
1198 bool unGet = !msgBase->isMessage();
1200 TQString result = msg->
from();
1206 TQString KMKernel::debugScheduler()
1208 TQString res = KMail::ActionScheduler::debug();
1212 TQString KMKernel::debugSernum( TQ_UINT32 serialNumber )
1215 if (serialNumber != 0) {
1222 if (folder && (idx != -1)) {
1227 res.append( TQString(
" subject %s,\n sender %s,\n date %s.\n" )
1228 .arg( msg->subject() )
1229 .arg( msg->fromStrip() )
1230 .arg( msg->dateStr() ) );
1232 res.append( TQString(
"Invalid serial number." ) );
1235 res.append( TQString(
"Invalid serial number." ) );
1244 mBackgroundTasksTimer->stop();
1245 mJobScheduler->pause();
1250 mJobScheduler->resume();
1251 mBackgroundTasksTimer->start( 4 * 60 * 60 * 1000,
true );
1256 if ( GlobalSettings::self()->networkState() == GlobalSettings::EnumNetworkState::Offline )
1259 GlobalSettings::setNetworkState( GlobalSettings::EnumNetworkState::Offline );
1260 BroadcastStatus::instance()->setStatusMsg( i18n(
"KMail is set to be offline; all network jobs are suspended"));
1261 emit onlineStatusChanged( (GlobalSettings::EnumNetworkState::type)GlobalSettings::networkState() );
1266 if ( GlobalSettings::self()->networkState() == GlobalSettings::EnumNetworkState::Online )
1269 GlobalSettings::setNetworkState( GlobalSettings::EnumNetworkState::Online );
1270 BroadcastStatus::instance()->setStatusMsg( i18n(
"KMail is set to be online; all network jobs resumed"));
1271 emit onlineStatusChanged( (GlobalSettings::EnumNetworkState::type)GlobalSettings::networkState() );
1273 if ( kmkernel->msgSender() && kmkernel->msgSender()->sendImmediate() ) {
1274 kmkernel->msgSender()->sendQueued();
1280 if ( GlobalSettings::self()->networkState() == GlobalSettings::EnumNetworkState::Offline )
1289 if ( s_askingToGoOnline ) {
1293 if ( kmkernel->isOffline() ) {
1294 s_askingToGoOnline =
true;
1297 i18n(
"KMail is currently in offline mode. "
1298 "How do you want to proceed?"),
1299 i18n(
"Online/Offline"),
1300 i18n(
"Work Online"),
1301 i18n(
"Work Offline"));
1303 s_askingToGoOnline =
false;
1304 if( rc == KMessageBox::No ) {
1307 kmkernel->resumeNetworkJobs();
1317 void KMKernel::quit()
1368 void KMKernel::testDir(
const char *_name)
1370 TQString foldersPath = TQDir::homeDirPath() + TQString( _name );
1371 TQFileInfo info( foldersPath );
1372 if ( !info.exists() ) {
1373 if ( ::mkdir( TQFile::encodeName( foldersPath ) , S_IRWXU ) == -1 ) {
1374 KMessageBox::sorry(0, i18n(
"KMail could not create folder '%1';\n"
1375 "please make sure that you can view and "
1376 "modify the content of the folder '%2'.")
1377 .arg( foldersPath ).arg( TQDir::homeDirPath() ) );
1381 if ( !info.isDir() || !info.isReadable() || !info.isWritable() ) {
1382 KMessageBox::sorry(0, i18n(
"The permissions of the folder '%1' are "
1384 "please make sure that you can view and modify "
1385 "the content of this folder.")
1386 .arg( foldersPath ) );
1394 void KMKernel::recoverDeadLetters()
1397 if ( !dir.exists() ) {
1398 kdWarning(5006) <<
"Autosave directory " << dir.path() <<
" not found!" << endl;
1402 const TQStringList entryList = dir.entryList( TQDir::Files | TQDir::NoSymLinks, TQDir::Unsorted );
1403 for (
unsigned int i = 0; i < entryList.size(); i++ ) {
1404 const TQString fileName = entryList[i];
1405 TQFile file( dir.path() +
'/' + fileName );
1406 if ( !file.open( IO_ReadOnly ) ) {
1407 kdWarning(5006) <<
"Unable to open autosave file " << fileName << endl;
1410 const TQByteArray msgData = file.readAll();
1413 if ( msgData.isEmpty() ) {
1414 kdWarning(5006) <<
"autosave file " << fileName <<
" is empty!" << endl;
1419 msg->fromByteArray( msgData );
1420 KMail::Composer * win = KMail::makeComposer();
1421 win->setMsg( msg,
false,
false,
true );
1422 win->setAutoSaveFilename( fileName );
1428 void KMKernel::initFolders(TDEConfig* cfg)
1432 name = cfg->readEntry(
"inboxFolder");
1438 if (name.isEmpty()) name = I18N_NOOP(
"inbox");
1440 the_inboxFolder = (
KMFolder*)the_folderMgr->findOrCreate(name);
1442 if (the_inboxFolder->
canAccess() != 0) {
1443 emergencyExit( i18n(
"You do not have read/write permission to your inbox folder.") );
1446 the_inboxFolder->setSystemFolder(
true);
1448 the_inboxFolder->setUserWhoField( TQString() );
1451 the_outboxFolder = the_folderMgr->findOrCreate(cfg->readEntry(
"outboxFolder", I18N_NOOP(
"outbox")));
1452 if (the_outboxFolder->
canAccess() != 0) {
1453 emergencyExit( i18n(
"You do not have read/write permission to your outbox folder.") );
1457 the_outboxFolder->setSystemFolder(
true);
1459 the_outboxFolder->setUserWhoField( TQString() );
1468 the_outboxFolder->
open(
"kmkernel");
1470 the_sentFolder = the_folderMgr->findOrCreate(cfg->readEntry(
"sentFolder", I18N_NOOP(
"sent-mail")));
1472 emergencyExit( i18n(
"You do not have read/write permission to your sent-mail folder.") );
1474 the_sentFolder->setSystemFolder(
true);
1476 the_sentFolder->setUserWhoField( TQString() );
1479 the_trashFolder = the_folderMgr->findOrCreate(cfg->readEntry(
"trashFolder", I18N_NOOP(
"trash")));
1480 if (the_trashFolder->
canAccess() != 0) {
1481 emergencyExit( i18n(
"You do not have read/write permission to your trash folder.") );
1483 the_trashFolder->setSystemFolder(
true );
1485 the_trashFolder->setUserWhoField( TQString() );
1488 the_draftsFolder = the_folderMgr->findOrCreate(cfg->readEntry(
"draftsFolder", I18N_NOOP(
"drafts")));
1489 if (the_draftsFolder->
canAccess() != 0) {
1490 emergencyExit( i18n(
"You do not have read/write permission to your drafts folder.") );
1492 the_draftsFolder->setSystemFolder(
true );
1494 the_draftsFolder->setUserWhoField( TQString() );
1495 the_draftsFolder->
open(
"kmkernel");
1497 the_templatesFolder =
1498 the_folderMgr->findOrCreate( cfg->readEntry(
"templatesFolder",
1499 I18N_NOOP(
"templates") ) );
1500 if ( the_templatesFolder->
canAccess() != 0 ) {
1501 emergencyExit( i18n(
"You do not have read/write permission to your templates folder.") );
1503 the_templatesFolder->setSystemFolder(
true );
1505 the_templatesFolder->setUserWhoField( TQString() );
1506 the_templatesFolder->
open(
"kmkernel");
1510 void KMKernel::init()
1512 the_shuttingDown =
false;
1513 the_server_is_ready =
false;
1515 TDEConfig* cfg = KMKernel::config();
1519 TDEConfigGroupSaver saver(cfg,
"General");
1520 the_firstStart = cfg->readBoolEntry(
"first-start",
true);
1521 cfg->writeEntry(
"first-start",
false);
1522 the_previousVersion = cfg->readEntry(
"previous-version");
1523 cfg->writeEntry(
"previous-version", KMAIL_VERSION);
1524 TQString foldersPath = cfg->readPathEntry(
"folders" );
1525 kdDebug(5006) << k_funcinfo <<
"foldersPath (from config): '" << foldersPath <<
"'" << endl;
1527 if ( foldersPath.isEmpty() ) {
1530 cfg->writePathEntry(
"folders", foldersPath );
1532 kdDebug(5006) << k_funcinfo <<
"foldersPath (after transferMail): '" << foldersPath <<
"'" << endl;
1538 the_undoStack =
new UndoStack(20);
1539 the_folderMgr =
new KMFolderMgr(foldersPath);
1540 the_imapFolderMgr =
new KMFolderMgr( KMFolderImap::cacheLocation(), KMImapDir);
1541 the_dimapFolderMgr =
new KMFolderMgr( KMFolderCachedImap::cacheLocation(), KMDImapDir);
1542 recreateCorruptIndexFiles();
1544 the_searchFolderMgr =
new KMFolderMgr(locateLocal(
"data",
"kmail/search"), KMSearchDir);
1545 KMFolder *lsf = the_searchFolderMgr->find( i18n(
"Last Search") );
1547 the_searchFolderMgr->remove( lsf );
1550 the_filterMgr =
new KMFilterMgr();
1551 the_popFilterMgr =
new KMFilterMgr(
true);
1556 the_filterMgr->readConfig();
1557 the_popFilterMgr->readConfig();
1558 cleanupImapFolders();
1560 the_msgSender =
new KMSender;
1561 the_server_is_ready =
true;
1564 TDEConfigGroupSaver saver(cfg,
"Composer");
1565 if (cfg->readListEntry(
"pref-charsets").isEmpty())
1567 cfg->writeEntry(
"pref-charsets",
"us-ascii,iso-8859-1,locale,utf-8");
1571 mICalIface->readConfig();
1573 #ifdef HAVE_INDEXLIB
1574 the_msgIndex =
new KMMsgIndex(
this);
1580 the_weaver =
new KPIM::ThreadWeaver::Weaver(
this );
1581 the_weaverLogger =
new KPIM::ThreadWeaver::WeaverThreadLogger(
this);
1582 the_weaverLogger->attach (the_weaver);
1585 connect( the_folderMgr, TQ_SIGNAL( folderRemoved(
KMFolder*) ),
1586 this, TQ_SIGNAL( folderRemoved(
KMFolder*) ) );
1587 connect( the_dimapFolderMgr, TQ_SIGNAL( folderRemoved(
KMFolder*) ),
1588 this, TQ_SIGNAL( folderRemoved(
KMFolder*) ) );
1589 connect( the_imapFolderMgr, TQ_SIGNAL( folderRemoved(
KMFolder*) ),
1590 this, TQ_SIGNAL( folderRemoved(
KMFolder*) ) );
1591 connect( the_searchFolderMgr, TQ_SIGNAL( folderRemoved(
KMFolder*) ),
1592 this, TQ_SIGNAL( folderRemoved(
KMFolder*) ) );
1594 mBackgroundTasksTimer =
new TQTimer(
this,
"mBackgroundTasksTimer" );
1595 connect( mBackgroundTasksTimer, TQ_SIGNAL( timeout() ),
this, TQ_SLOT( slotRunBackgroundTasks() ) );
1596 #ifdef DEBUG_SCHEDULER
1597 mBackgroundTasksTimer->start( 10000,
true );
1599 mBackgroundTasksTimer->start( 5 * 60000,
true );
1603 for (
int i = 0; ( codec = TQTextCodec::codecForIndex ( i ) ); i++ ) {
1604 const TQString asciiString(
"azAZ19,.-#+!?=()&" );
1605 const TQCString encodedString = codec->fromUnicode( asciiString );
1606 if ( TQString::fromAscii( encodedString ) != asciiString ) {
1607 mNonAsciiCompatibleCodecs.append( codec );
1612 bool KMKernel::isCodecAsciiCompatible(
const TQTextCodec *codec )
1614 return !mNonAsciiCompatibleCodecs.contains( codec );
1617 void KMKernel::readConfig()
1624 void KMKernel::cleanupImapFolders()
1626 KMAccount *acct = 0;
1627 KMFolderNode *node = the_imapFolderMgr->dir().first();
1630 if (node->isDir() || ((acct = the_acctMgr->
find(node->id()))
1631 && ( acct->type() ==
"imap" )) )
1633 node = the_imapFolderMgr->dir().next();
1637 static_cast<KMFolderImap*
>( folder->storage() )->setAlreadyRemoved(
true );
1638 the_imapFolderMgr->remove(folder);
1639 node = the_imapFolderMgr->dir().first();
1643 node = the_dimapFolderMgr->dir().first();
1646 if (node->isDir() || ((acct = the_acctMgr->
find(node->id()))
1647 && ( acct->type() ==
"cachedimap" )) )
1649 node = the_dimapFolderMgr->dir().next();
1651 the_dimapFolderMgr->remove(
static_cast<KMFolder*
>(node));
1652 node = the_dimapFolderMgr->dir().first();
1656 the_imapFolderMgr->quiet(
true);
1657 for (acct = the_acctMgr->
first(); acct; acct = the_acctMgr->
next())
1660 KMAcctImap *imapAcct;
1662 if (acct->type() !=
"imap")
continue;
1663 fld =
static_cast<KMFolderImap*
>(the_imapFolderMgr
1664 ->findOrCreate(TQString::number(acct->id()),
false, acct->id())->storage());
1665 fld->setNoContent(
true);
1666 fld->folder()->setLabel(acct->name());
1667 imapAcct =
static_cast<KMAcctImap*
>(acct);
1668 fld->setAccount(imapAcct);
1669 imapAcct->setImapFolder(fld);
1670 fld->close(
"kernel",
true );
1672 the_imapFolderMgr->quiet(
false);
1674 the_dimapFolderMgr->quiet(
true );
1675 for (acct = the_acctMgr->
first(); acct; acct = the_acctMgr->
next())
1677 KMFolderCachedImap *cfld = 0;
1678 KMAcctCachedImap *cachedImapAcct;
1680 if (acct->type() !=
"cachedimap" )
continue;
1682 KMFolder* fld = the_dimapFolderMgr->find(TQString::number(acct->id()));
1684 cfld =
static_cast<KMFolderCachedImap*
>( fld->storage() );
1687 cfld =
static_cast<KMFolderCachedImap*
>(the_dimapFolderMgr->createFolder(TQString::number(acct->id()),
1688 false, KMFolderTypeCachedImap)->storage());
1690 KMessageBox::error(0,(i18n(
"Cannot create file `%1' in %2.\nKMail cannot start without it.").arg(acct->name()).arg(the_dimapFolderMgr->basePath())));
1693 cfld->folder()->setId( acct->id() );
1696 cfld->setNoContent(
true);
1697 cfld->folder()->setLabel(acct->name());
1698 cachedImapAcct =
static_cast<KMAcctCachedImap*
>(acct);
1699 cfld->setAccount(cachedImapAcct);
1700 cachedImapAcct->setImapFolder(cfld);
1701 cfld->close(
"kmkernel");
1703 the_dimapFolderMgr->quiet(
false );
1706 void KMKernel::recreateCorruptIndexFiles()
1708 TQValueList<TQGuardedPtr<KMFolder> > folders;
1709 TQValueList<KMFolderIndex*> foldersWithBrokenIndex;
1710 TQStringList strList;
1711 the_folderMgr->createFolderList( &strList, &folders );
1712 the_imapFolderMgr->createFolderList( &strList, &folders );
1713 the_dimapFolderMgr->createFolderList( &strList, &folders );
1714 for (
int i = 0; folders.at(i) != folders.end(); i++ ) {
1715 KMFolder *
const folder = *folders.at(i);
1716 if ( !folder || folder->isDir() || folder->
isOpened() )
1719 if ( index && index->
indexStatus() != KMFolderIndex::IndexOk ) {
1720 foldersWithBrokenIndex.append( index );
1724 if ( !foldersWithBrokenIndex.isEmpty() ) {
1725 TQStringList folderNames;
1726 for ( uint i = 0; i < foldersWithBrokenIndex.size(); i++ ) {
1727 folderNames << foldersWithBrokenIndex[i]->
label();
1730 KMessageBox::informationList( 0, i18n(
"There is a problem with the mail index of the following "
1731 "folders, the indices will now be regenerated.\n"
1732 "This can happen because the index files are out of date, missing or corrupted.\n"
1733 "Contact your administrator if this happens frequently.\n"
1734 "Some information, like status flags, might get lost." ),
1735 folderNames, i18n(
"Problem with mail indices" ) );
1737 for ( uint i = 0; i < foldersWithBrokenIndex.size(); i++ ) {
1738 foldersWithBrokenIndex[i]->silentlyRecreateIndex();
1743 bool KMKernel::doSessionManagement()
1747 if (kapp->isRestored()){
1749 while (KMMainWin::canBeRestored(n)){
1751 if (KMMainWin::classNameOfToplevel(n) ==
"KMMainWin")
1752 (
new KMMainWin)->restore(n);
1760 void KMKernel::closeAllKMailWindows()
1762 if (!TDEMainWindow::memberList)
return;
1763 TQPtrListIterator<TDEMainWindow> it(*TDEMainWindow::memberList);
1764 TDEMainWindow *window = 0;
1765 while ((window = it.current()) != 0) {
1767 if (window->isA(
"KMMainWindow") ||
1768 window->inherits(
"KMail::SecondaryWindow"))
1769 window->close(
true );
1773 void KMKernel::cleanup(
void)
1776 the_shuttingDown =
true;
1777 closeAllKMailWindows();
1781 delete the_filterMgr;
1783 delete the_msgSender;
1785 delete the_filterActionDict;
1786 the_filterActionDict = 0;
1787 delete the_undoStack;
1789 delete the_popFilterMgr;
1790 the_popFilterMgr = 0;
1797 TDEConfig* config = KMKernel::config();
1798 TDEConfigGroupSaver saver(config,
"General");
1800 if (the_trashFolder) {
1802 the_trashFolder->
close(
"kmkernel",
true);
1804 if (config->readBoolEntry(
"empty-trash-on-exit",
true))
1806 if ( the_trashFolder->
count(
true ) > 0 )
1813 TQValueList<TQGuardedPtr<KMFolder> > folders;
1814 TQStringList strList;
1816 the_folderMgr->createFolderList(&strList, &folders);
1817 for (
int i = 0; folders.at(i) != folders.end(); i++)
1819 folder = *folders.at(i);
1820 if (!folder || folder->isDir())
continue;
1821 folder->
close(
"kmkernel",
true);
1825 the_searchFolderMgr->createFolderList(&strList, &folders);
1826 for (
int i = 0; folders.at(i) != folders.end(); i++)
1828 folder = *folders.at(i);
1829 if (!folder || folder->isDir())
continue;
1830 folder->
close(
"kmkernel",
true);
1833 delete the_msgIndex;
1835 delete the_folderMgr;
1837 delete the_imapFolderMgr;
1838 the_imapFolderMgr = 0;
1839 delete the_dimapFolderMgr;
1840 the_dimapFolderMgr = 0;
1841 delete the_searchFolderMgr;
1842 the_searchFolderMgr = 0;
1843 delete mConfigureDialog;
1844 mConfigureDialog = 0;
1849 if ( RecentAddresses::exists() )
1850 RecentAddresses::self( config )->save( config );
1859 TQFileInfo fi( TQDir::home(),
"KMail" );
1860 if ( fi.exists() && fi.isDir() ) {
1861 dir = TQDir::homeDirPath() +
"/KMail";
1863 destinationDir = dir;
1867 if ( dir.isEmpty() ) {
1869 fi.setFile( TQDir::home(),
"Mail" );
1870 if ( fi.exists() && fi.isDir() &&
1871 TQFile::exists( TQDir::homeDirPath() +
"/Mail/.inbox.index" ) ) {
1874 dir = TQDir::homeDirPath() +
"/Mail";
1876 destinationDir = dir;
1881 if ( dir.isEmpty() ) {
1887 const TQString kmailName = kapp->aboutData()->programName();
1889 if ( TDEIO::NetAccess::exists( destinationDir,
true, 0 ) ) {
1892 msg = i18n(
"%1-%3 is the application name, %4-%7 are folder path",
1893 "<qt>The <i>%4</i> folder exists. "
1894 "%1 now uses the <i>%5</i> folder for "
1896 "%2 can move the contents of <i>%6<i> into this folder for "
1897 "you, though this may replace any existing files with "
1898 "the same name in <i>%7</i>.<p>"
1899 "<strong>Would you like %3 to move the mail "
1900 "files now?</strong></qt>" )
1901 .arg( kmailName, kmailName, kmailName )
1902 .arg( dir, destinationDir, dir, destinationDir );
1904 msg = i18n(
"%1-%3 is the application name, %4-%6 are folder path",
1905 "<qt>The <i>%4</i> folder exists. "
1906 "%1 now uses the <i>%5</i> folder for "
1907 "its messages. %2 can move the contents of <i>%6</i> into "
1908 "this folder for you.<p>"
1909 "<strong>Would you like %3 to move the mail "
1910 "files now?</strong></qt>" )
1911 .arg( kmailName, kmailName, kmailName )
1912 .arg( dir, destinationDir, dir );
1914 TQString title = i18n(
"Migrate Mail Files?" );
1915 TQString buttonText = i18n(
"Move" );
1917 if ( KMessageBox::questionYesNo( 0, msg, title, buttonText, i18n(
"Do Not Move") ) ==
1919 destinationDir = dir;
1923 if ( !TDEIO::NetAccess::move( dir, destinationDir ) ) {
1924 kdDebug(5006) << k_funcinfo <<
"Moving " << dir <<
" to " << destinationDir <<
" failed: " << TDEIO::NetAccess::lastErrorString() << endl;
1925 kdDebug(5006) << k_funcinfo <<
"Deleting " << destinationDir << endl;
1926 TDEIO::NetAccess::del( destinationDir, 0 );
1927 destinationDir = dir;
1936 void KMKernel::ungrabPtrKb(
void)
1938 if(!TDEMainWindow::memberList)
return;
1939 TQWidget* widg = TDEMainWindow::memberList->first();
1943 dpy = widg->x11Display();
1944 XUngrabKeyboard(dpy, CurrentTime);
1945 XUngrabPointer(dpy, CurrentTime);
1950 void KMKernel::kmailMsgHandler(TQtMsgType aType,
const char* aMsg)
1952 static int recurse=-1;
1960 kdDebug(5006) << aMsg << endl;
1965 kdDebug(5006) << kapp->caption() <<
" fatal error "
1967 KMessageBox::error(0, aMsg);
1977 if ( shuttingDown() )
1981 if ( !TDEMainWindow::memberList )
1984 for ( TQPtrListIterator<TDEMainWindow> it(*TDEMainWindow::memberList) ; it.current() != 0; ++it ) {
1985 if ( KMail::Composer * win = ::tqt_cast<KMail::Composer*>( it.current() ) ) {
1986 win->autoSaveMessage();
1991 while ( win->isComposing() )
1992 tqApp->processEvents();
1999 void KMKernel::action(
bool mailto,
bool check,
const TQString &to,
2000 const TQString &cc,
const TQString &bcc,
2001 const TQString &subj,
const TQString &body,
2002 const KURL &messageFile,
2003 const KURL::List &attachURLs,
2004 const QCStringList &customHeaders)
2007 openComposer( to, cc, bcc, subj, body, 0, messageFile, attachURLs, customHeaders );
2009 openReader( check );
2016 void KMKernel::byteArrayToRemoteFile(
const TQByteArray &aData,
const KURL &aURL,
2020 TDEIO::Job *job = TDEIO::put(aURL, -1, overwrite,
false);
2021 putData pd; pd.url = aURL; pd.data = aData; pd.offset = 0;
2022 mPutJobs.insert(job, pd);
2023 connect(job, TQ_SIGNAL(dataReq(TDEIO::Job*,TQByteArray&)),
2024 TQ_SLOT(slotDataReq(TDEIO::Job*,TQByteArray&)));
2025 connect(job, TQ_SIGNAL(result(TDEIO::Job*)),
2026 TQ_SLOT(slotResult(TDEIO::Job*)));
2029 void KMKernel::slotDataReq(TDEIO::Job *job, TQByteArray &data)
2032 const int MAX_CHUNK_SIZE = 64*1024;
2033 TQMap<TDEIO::Job*, putData>::Iterator it = mPutJobs.find(job);
2034 assert(it != mPutJobs.end());
2035 int remainingBytes = (*it).data.size() - (*it).offset;
2036 if( remainingBytes > MAX_CHUNK_SIZE )
2039 data.duplicate( (*it).data.data() + (*it).offset, MAX_CHUNK_SIZE );
2040 (*it).offset += MAX_CHUNK_SIZE;
2047 data.duplicate( (*it).data.data() + (*it).offset, remainingBytes );
2048 (*it).data = TQByteArray();
2054 void KMKernel::slotResult(TDEIO::Job *job)
2056 TQMap<TDEIO::Job*, putData>::Iterator it = mPutJobs.find(job);
2057 assert(it != mPutJobs.end());
2060 if (job->error() == TDEIO::ERR_FILE_ALREADY_EXIST)
2062 if (KMessageBox::warningContinueCancel(0,
2063 i18n(
"File %1 exists.\nDo you want to replace it?")
2064 .arg((*it).url.prettyURL()), i18n(
"Save to File"), i18n(
"&Replace"))
2065 == KMessageBox::Continue)
2066 byteArrayToRemoteFile((*it).data, (*it).url,
true);
2068 else job->showErrorDialog();
2070 mPutJobs.remove(it);
2075 KMKernel::config()->sync();
2078 void KMKernel::slotShowConfigurationDialog()
2080 if( !mConfigureDialog ) {
2081 mConfigureDialog =
new ConfigureDialog( 0,
"configure",
false );
2082 connect( mConfigureDialog, TQ_SIGNAL( configChanged() ),
2083 this, TQ_SLOT( slotConfigChanged() ) );
2091 KMMainWin * win =
new KMMainWin;
2094 if( mConfigureDialog->isHidden() )
2097 mConfigureDialog->show();
2100 mConfigureDialog->raise();
2103 void KMKernel::slotConfigChanged()
2106 emit configChanged();
2113 return locateLocal(
"data",
"kmail/" );
2120 return !systemTrayApplets.isEmpty();
2123 bool KMKernel::registerSystemTrayApplet(
const KSystemTray* applet )
2125 if ( systemTrayApplets.findIndex( applet ) == -1 ) {
2126 systemTrayApplets.append( applet );
2133 bool KMKernel::unregisterSystemTrayApplet(
const KSystemTray* applet )
2135 TQValueList<const KSystemTray*>::iterator it =
2136 systemTrayApplets.find( applet );
2137 if ( it != systemTrayApplets.end() ) {
2138 systemTrayApplets.remove( it );
2145 void KMKernel::emergencyExit(
const TQString& reason )
2148 if ( reason.length() == 0 ) {
2149 mesg = i18n(
"KMail encountered a fatal error and will terminate now");
2151 mesg = i18n(
"KMail encountered a fatal error and will "
2152 "terminate now.\nThe error was:\n%1").arg( reason );
2155 kdWarning() << mesg << endl;
2156 KNotifyClient::userEvent( 0,
"<qt>"+mesg+
"</qt>", KNotifyClient::Messagebox, KNotifyClient::Error );
2167 if ( folder == the_outboxFolder )
2169 return folderIsDrafts( folder );
2172 bool KMKernel::folderIsDrafts(
const KMFolder * folder)
2175 if ( folder == the_draftsFolder )
2178 TQString idString = folder->
idString();
2179 if ( idString.isEmpty() )
2184 for ( KPIM::IdentityManager::ConstIterator it=im->begin(); it != im->end(); ++it )
2185 if ( (*it).drafts() == idString )
2190 bool KMKernel::folderIsTemplates(
const KMFolder *folder )
2193 if ( folder == the_templatesFolder )
2196 TQString idString = folder->
idString();
2197 if ( idString.isEmpty() )
2202 for ( KPIM::IdentityManager::ConstIterator it=im->begin(); it != im->end(); ++it )
2203 if ( (*it).templates() == idString )
2208 bool KMKernel::folderIsTrash(
KMFolder * folder)
2211 if (folder == the_trashFolder)
return true;
2212 TQStringList actList = acctMgr()->getAccounts();
2213 TQStringList::Iterator it( actList.begin() );
2214 for( ; it != actList.end() ; ++it ) {
2215 KMAccount* act = acctMgr()->
findByName( *it );
2216 if ( act && ( act->trash() == folder->
idString() ) )
2225 if ( folder == the_sentFolder )
2228 TQString idString = folder->
idString();
2229 if ( idString.isEmpty() )
return false;
2233 for( KPIM::IdentityManager::ConstIterator it = im->begin(); it != im->end(); ++it )
2234 if ( (*it).fcc() == idString )
return true;
2239 if ( !mIdentityManager ) {
2240 kdDebug(5006) <<
"instantating KPIM::IdentityManager" << endl;
2241 mIdentityManager =
new KPIM::IdentityManager(
false,
this,
"mIdentityManager" );
2243 return mIdentityManager;
2246 KMMsgIndex *KMKernel::msgIndex()
2248 return the_msgIndex;
2253 if (TDEMainWindow::memberList) {
2254 TDEMainWindow *kmWin = 0;
2257 for (kmWin = TDEMainWindow::memberList->first(); kmWin;
2258 kmWin = TDEMainWindow::memberList->next())
2259 if (kmWin->isA(
"KMMainWin"))
2265 kmWin = TDEMainWindow::memberList->first();
2274 mWin =
new KMMainWin;
2284 TQString title = i18n(
"Empty Trash");
2285 TQString text = i18n(
"Are you sure you want to empty the trash folders of all accounts?");
2286 if (KMessageBox::warningContinueCancel(0, text, title,
2287 KStdGuiItem::cont(),
"confirm_empty_trash")
2288 != KMessageBox::Continue)
2293 for (KMAccount* acct = acctMgr()->first(); acct; acct = acctMgr()->
next())
2303 TDEConfig* KMKernel::config()
2306 if (!mySelf->mConfig)
2308 mySelf->mConfig = TDESharedConfig::openConfig(
"kmailrc" );
2310 KMail::checkConfigUpdates();
2312 return mySelf->mConfig;
2317 assert( mICalIface );
2321 void KMKernel::selectFolder( TQString folderPath )
2323 kdDebug(5006)<<
"Selecting a folder "<<folderPath<<endl;
2324 const TQString localPrefix =
"/Local";
2325 KMFolder *folder = kmkernel->folderMgr()->getFolderByURL( folderPath );
2326 if ( !folder && folderPath.startsWith( localPrefix ) )
2327 folder = the_folderMgr->getFolderByURL( folderPath.mid( localPrefix.length() ) );
2329 folder = kmkernel->imapFolderMgr()->getFolderByURL( folderPath );
2331 folder = kmkernel->dimapFolderMgr()->getFolderByURL( folderPath );
2339 KMFolderTree *tree = widget->folderTree();
2340 tree->doFolderSelected( tree->indexOfFolder( folder ) );
2341 tree->ensureItemVisible( tree->indexOfFolder( folder ) );
2347 TQWidgetList *l = kapp->topLevelWidgets();
2348 TQWidgetListIt it( *l );
2351 while ( ( wid = it.current() ) != 0 ) {
2353 TQObjectList *l2 = wid->topLevelWidget()->queryList(
"KMMainWidget" );
2354 if (l2 && l2->first()) {
2355 KMMainWidget* kmmw =
dynamic_cast<KMMainWidget *
>( l2->first() );
2367 void KMKernel::slotRunBackgroundTasks()
2371 TDEConfigGroup generalGroup( config(),
"General" );
2373 if ( generalGroup.readBoolEntry(
"auto-expiring",
true ) ) {
2374 the_folderMgr->expireAllFolders(
false );
2375 the_imapFolderMgr->expireAllFolders(
false );
2376 the_dimapFolderMgr->expireAllFolders(
false );
2380 if ( generalGroup.readBoolEntry(
"auto-compaction",
true ) ) {
2381 the_folderMgr->compactAllFolders(
false );
2383 the_dimapFolderMgr->compactAllFolders(
false );
2387 #ifdef DEBUG_SCHEDULER
2388 mBackgroundTasksTimer->start( 60 * 1000,
true );
2390 mBackgroundTasksTimer->start( 4 * 60 * 60 * 1000,
true );
2397 the_folderMgr->expireAllFolders(
true );
2398 the_imapFolderMgr->expireAllFolders(
true );
2399 the_dimapFolderMgr->expireAllFolders(
true );
2404 the_folderMgr->compactAllFolders(
true );
2406 the_dimapFolderMgr->compactAllFolders(
true );
2411 KMFolder * folder = the_folderMgr->findIdString( idString );
2413 folder = the_imapFolderMgr->findIdString( idString );
2415 folder = the_dimapFolderMgr->findIdString( idString );
2417 folder = the_searchFolderMgr->findIdString( idString );
2423 return KIMProxy::instance( kapp->dcopClient() );
2428 mMailCheckAborted =
false;
2433 return mMailCheckAborted;
2438 mMailCheckAborted =
true;
2441 bool KMKernel::canQueryClose()
2443 if ( KMMainWidget::mainWidgetList() &&
2444 KMMainWidget::mainWidgetList()->count() > 1 )
2450 if ( !systray || GlobalSettings::closeDespiteSystemTray() )
2452 if ( systray->mode() == GlobalSettings::EnumSystemTrayPolicy::ShowAlways ) {
2453 systray->hideKMail();
2455 }
else if ( ( systray->mode() == GlobalSettings::EnumSystemTrayPolicy::ShowOnUnread ) && ( systray->hasUnreadMail() )) {
2457 systray->hideKMail();
2465 mTimeOfLastMessageCountChange = ::time( 0 );
2468 int KMKernel::timeOfLastMessageCountChange()
const
2470 return mTimeOfLastMessageCountChange;
2473 bool KMKernel::networkStateConnected()
2475 #ifdef __TDE_HAVE_TDEHWLIB
2476 if (mNetworkManager) {
2477 TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags networkStatus = mNetworkManager->backendStatus();
2478 if ((networkStatus & TDENetworkGlobalManagerFlags::Connected)
2479 || (networkStatus & TDENetworkGlobalManagerFlags::BackendUnavailable)
2480 || (networkStatus == TDENetworkGlobalManagerFlags::Unknown)
2498 void KMKernel::slotNetworkStateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus, TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString)
2500 if (networkStateConnected()) {
2509 static bool walletOpenFailed =
false;
2510 if ( mWallet && mWallet->isOpen() )
2513 if ( !Wallet::isEnabled() || walletOpenFailed )
2518 if ( tqApp->activeWindow() )
2519 window = tqApp->activeWindow()->winId();
2524 mWallet = Wallet::openWallet( Wallet::NetworkWallet(), window );
2527 walletOpenFailed =
true;
2531 if ( !mWallet->hasFolder(
"kmail" ) )
2532 mWallet->createFolder(
"kmail" );
2533 mWallet->setFolder(
"kmail" );
2540 TQValueList<TQGuardedPtr<KMFolder> > folders;
2541 folderMgr()->createFolderList(&names, &folders);
2542 imapFolderMgr()->createFolderList(&names, &folders);
2543 dimapFolderMgr()->createFolderList(&names, &folders);
2544 searchFolderMgr()->createFolderList(&names, &folders);
2549 KMFolder *KMKernel::currentFolder() {
2552 if ( widget && widget->folderTree() ) {
2553 folder = widget->folderTree()->currentFolder();
2560 KMail::MessageSender * KMKernel::msgSender() {
return the_msgSender; }
2562 #include "kmkernel.moc"
TQString label() const
Returns the label of the folder for visualization.
Dictionary that contains a list of all registered filter actions with their creation functions.
KMail list that manages the contents of one directory that may contain folders and/or other directori...
A FolderStorage with an index for faster access to often used message properties.
virtual IndexStatus indexStatus()=0
Tests whether the contents of this folder is newer than the index.
RAII for KMFolder::open() / close().
bool isOpened() const
Test if folder is opened.
void setNoChildren(bool aNoChildren)
Specify, that the folder can't have children.
TQString idString() const
Returns a string that can be used to identify this folder.
KMMsgInfo * unGetMsg(int idx)
Replace KMMessage with KMMsgInfo and delete KMMessage
int canAccess()
Check folder for permissions Returns zero if readable and writable.
int addMsg(KMMessage *msg, int *index_return=0)
Add the given message to the folder.
int expunge()
Delete entire folder.
void close(const char *owner, bool force=false)
Close folder.
KMFolderDir * createChildFolder()
Create a child folder directory and associates it with this folder.
KMMessage * getMsg(int idx)
Read message at given index.
const KMMsgBase * getMsgBase(int idx) const
Provides access to the basic message fields that are also stored in the index.
KMFolderType folderType() const
Returns the type of this folder.
int count(bool cache=false) const
Number of messages in this folder.
int open(const char *owner)
Open folder for access.
TQString userWhoField(void)
Get / set the user-settings for the WhoField (From/To/Empty)
Central point of coordination in KMail.
void expireAllFoldersNow()
Expire all folders, used for the gui action.
virtual void pauseBackgroundJobs()
Pauses all background jobs and does not allow new background jobs to be started.
void compactAllFolders()
Compact all folders, used for the gui action (and from DCOP)
void dumpDeadLetters()
Save contents of all open composer widnows to ~/dead.letter.
::KIMProxy * imProxy()
Get a reference to KMail's KIMProxy instance.
void dcopResetAddMessage()
Clears the list of added message ids which is used to filter out duplicates.
int dcopAddMessage(const TQString &foldername, const TQString &messagefile, const TQString &MsgStatusFlags=TQString())
bool folderIsDraftOrOutbox(const KMFolder *)
Returns true if the folder is either the outbox or one of the drafts-folders.
int openComposer(const TQString &to, const TQString &cc, const TQString &bcc, const TQString &subject, const TQString &body, int hidden, const KURL &messageFile, const KURL::List &attachURLs, const QCStringList &customHeaders)
returns id of composer if more are opened
bool mailCheckAborted() const
Returns true IFF the user has requested that the current mail checks should be aborted.
void checkMail()
dcop callable stuff
virtual bool showMail(TQ_UINT32 serialNumber, TQString messageId)
Shows the specified message in a separate message window.
int sendCertificate(const TQString &to, const TQByteArray &certData)
Send a certificate request to the CA specified in to.
virtual TQString getFrom(TQ_UINT32 serialNumber)
DCOP-enabled for use in kaddressbook drop.
static bool askToGoOnline()
A static helper function that asks the user if they want to go online.
TQValueList< TQGuardedPtr< KMFolder > > allFolders()
static KMKernel * self()
normal control stuff
DCOPRef newMessage(const TQString &to, const TQString &cc, const TQString &bcc, bool hidden, bool useFolderId, const KURL &messageFile, const KURL &attachURL)
DCOP call used by the Kontact plugin to create a new message.
bool haveSystemTrayApplet()
Returns true if we have a system tray applet.
bool folderIsSentMailFolder(const KMFolder *)
Returns true if the folder is one of the sent-mail folders.
KMMainWidget * getKMMainWidget()
Get first mainwidget.
void stopNetworkJobs()
Stops all network related jobs and enter offline mode New network jobs cannot be started.
KPIM::IdentityManager * identityManager()
return the pointer to the identity manager
TDEWallet::Wallet * wallet()
Open KDE wallet and set it to kmail folder.
virtual void resumeBackgroundJobs()
Resumes all background jobs and allows new jobs to be started.
TDEMainWindow * mainWin()
returns a reference to the first Mainwin or a temporary Mainwin
bool transferMail(TQString &destinationDir)
Returns true if the transfer was successful, otherwise false.
void abortMailCheck()
Set the state of the abort requested variable to true, (to let the current jobs run,...
void slotRequestConfigSync()
Call this slot instead of directly TDEConfig::sync() to minimize the overall config writes.
void setDefaultTransport(const TQString &transport)
DCOP call used to set the default transport.
static bool isOffline()
Checks if the current network state is online or offline.
int dcopAddMessage_fastImport(const TQString &foldername, const TQString &messagefile, const TQString &MsgStatusFlags=TQString())
add messages without rejecting duplicates
bool handleCommandLine(bool noArgsOpensReader)
Reimplemented from KMailIface.
void resumeNetworkJobs()
Resumes all network related jobs and enter online mode New network jobs can be started.
KMFolder * findFolderById(const TQString &idString)
Find a folder by ID string in all folder managers.
static TQString localDataPath()
Returns the full path of the user's local data directory for KMail.
void slotEmptyTrash()
empty all the trash bins
void enableMailCheck()
Set the state of the abort requested variable to false, i.e.
void messageCountChanged()
Called by the folder tree if the count of unread/total messages changed.
void setBody(const TQCString &aStr)
Set the message body.
TQString from() const
Get or set the 'From' header field.
void setCharset(const TQCString &charset, DwEntity *entity=0)
Sets the charset of the message or a subpart of the message.
static void readConfig()
Reads config settings from group "KMMessage" and sets all internal variables (e.g.
void setStatus(const KMMsgStatus status, int idx=-1)
Set status and mark dirty.
TQString subject() const
Get or set the 'Subject' header field.
void initHeader(uint identity=0)
Initialize header fields.
void setHeaderField(const TQCString &name, const TQString &value, HeaderFieldType type=Unstructured, bool prepend=false)
Set the header field with the given name to the given value.
TQString dateStr() const
Get or set the 'Date' header field.
void getLocation(unsigned long key, KMFolder **retFolder, int *retIndex) const
Returns the folder the message represented by the serial number key is in and the index in that folde...
static const KMMsgDict * instance()
Access the globally unique MessageDict.
KMSystemTray extends KSystemTray and handles system tray notification for KMail.
The implementation of the interface.
void cleanup()
Disconnect all slots and close the dirs.
The account manager is responsible for creating accounts of various types via the factory method crea...
void readConfig(void)
Completely reload accounts from config.
KMAccount * findByName(const TQString &name) const
Find account by name.
const KMAccount * first() const
First account of the list.
const KMAccount * next() const
Next account of the list.
KMAccount * find(const uint id) const
Find account by id.
The unique JobScheduler instance (owned by kmkernel) implements "background processing" of folder ope...
static TQStringList transportNames()
Returns the list for transport names.
The TemplateParser transforms a message with a given template.