korganizer

mailscheduler.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include <qdir.h>
00026 #include <qfile.h>
00027 #include <qregexp.h>
00028 
00029 #include <kstandarddirs.h>
00030 #include <kdebug.h>
00031 
00032 #include <libkcal/event.h>
00033 #include <libkcal/icalformat.h>
00034 
00035 #include "komailclient.h"
00036 
00037 #include "mailscheduler.h"
00038 
00039 
00040 using namespace KCal;
00041 
00042 MailScheduler::MailScheduler( Calendar *calendar )
00043   : IMIPScheduler( calendar )
00044 {
00045 }
00046 
00047 MailScheduler::~MailScheduler()
00048 {
00049 }
00050 
00051 bool MailScheduler::publish( IncidenceBase *incidence,
00052                              const QString &recipients )
00053 {
00054   QString messageText = mFormat->createScheduleMessage( incidence,
00055                                                         Scheduler::Publish );
00056   KOMailClient mailer;
00057   return mailer.mailTo( incidence, recipients, messageText );
00058 }
00059 
00060 bool MailScheduler::performTransaction( IncidenceBase *incidence,
00061                                         Method method,
00062                                         const QString &recipients )
00063 {
00064   QString messageText = mFormat->createScheduleMessage( incidence, method );
00065 
00066   KOMailClient mailer;
00067   return mailer.mailTo( incidence, recipients, messageText );
00068 }
00069 
00070 bool MailScheduler::performTransaction( IncidenceBase *incidence,
00071                                         Method method )
00072 {
00073   QString messageText = mFormat->createScheduleMessage( incidence, method );
00074 
00075   KOMailClient mailer;
00076   bool status;
00077   if ( method == Request ||
00078        method == Cancel ||
00079        method == Add ||
00080        method == Declinecounter ) {
00081     status = mailer.mailAttendees( incidence, messageText );
00082   } else {
00083     status = mailer.mailOrganizer( incidence, messageText );
00084   }
00085   return status;
00086 }
00087 
00088 QPtrList<ScheduleMessage> MailScheduler::retrieveTransactions()
00089 {
00090   QString incomingDirName = locateLocal( "data", "korganizer/income" );
00091   kdDebug(5850) << "MailScheduler::retrieveTransactions: dir: "
00092                 << incomingDirName << endl;
00093 
00094   QPtrList<ScheduleMessage> messageList;
00095 
00096   QDir incomingDir( incomingDirName );
00097   QStringList incoming = incomingDir.entryList( QDir::Files );
00098   QStringList::ConstIterator it;
00099   for( it = incoming.begin(); it != incoming.end(); ++it ) {
00100     kdDebug(5850) << "-- File: " << (*it) << endl;
00101 
00102     QFile f( incomingDirName + "/" + (*it) );
00103     bool inserted = false;
00104     QMap<IncidenceBase*, QString>::Iterator iter;
00105     for ( iter = mEventMap.begin(); iter != mEventMap.end(); ++iter ) {
00106       if ( iter.data() == incomingDirName + "/" + (*it) )
00107         inserted = true;
00108     }
00109     if ( !inserted ) {
00110       if ( !f.open( IO_ReadOnly ) ) {
00111         kdDebug(5850)
00112           << "MailScheduler::retrieveTransactions(): Can't open file'"
00113           << (*it) << "'" << endl;
00114       } else {
00115         QTextStream t( &f );
00116         t.setEncoding( QTextStream::Latin1 );
00117         QString messageString = t.read();
00118         messageString.replace( QRegExp( "\n[ \t]"), "" );
00119         messageString = QString::fromUtf8( messageString.latin1() );
00120         ScheduleMessage *mess = mFormat->parseScheduleMessage( mCalendar,
00121                                                                messageString );
00122         if ( mess) {
00123           kdDebug(5850)
00124             << "MailScheduler::retrieveTransactions: got message '"
00125             << (*it) << "'" << endl;
00126           messageList.append( mess );
00127           mEventMap[ mess->event() ] = incomingDirName + "/" + (*it);
00128         } else {
00129           QString errorMessage;
00130           if ( mFormat->exception() ) {
00131             errorMessage = mFormat->exception()->message();
00132           }
00133           kdDebug(5850)
00134             << "MailScheduler::retrieveTransactions() Error parsing message: "
00135             << errorMessage << endl;
00136         }
00137         f.close();
00138       }
00139     }
00140   }
00141   return messageList;
00142 }
00143 
00144 bool MailScheduler::deleteTransaction( IncidenceBase *incidence )
00145 {
00146   bool status;
00147   QFile f( mEventMap[incidence] );
00148   mEventMap.remove( incidence );
00149   if ( !f.exists() ) {
00150     status = false;
00151   } else {
00152     status = f.remove();
00153   }
00154   return status;
00155 }
00156 
00157 QString MailScheduler::freeBusyDir()
00158 {
00159   return locateLocal( "data", "korganizer/freebusy" );
00160 }
KDE Home | KDE Accessibility Home | Description of Access Keys