kmail Library API Documentation

callback.cpp

00001 /*  -*- c++ -*-
00002     callback.cpp
00003 
00004     This file is used by KMail's plugin interface.
00005     Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
00006 
00007     KMail is free software; you can redistribute it and/or modify it
00008     under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     KMail is distributed in the hope that it will be useful, but
00013     WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     In addition, as a special exception, the copyright holders give
00022     permission to link the code of this program with any edition of
00023     the Qt library by Trolltech AS, Norway (or with modified versions
00024     of Qt that use the same license as Qt), and distribute linked
00025     combinations including the two.  You must obey the GNU General
00026     Public License in all respects for all of the code used other than
00027     Qt.  If you modify this file, you may extend this exception to
00028     your version of the file, but you are not obligated to do so.  If
00029     you do not wish to do so, delete this exception statement from
00030     your version.
00031 */
00032 
00033 #include "callback.h"
00034 #include "kmkernel.h"
00035 #include "kmmessage.h"
00036 #include <libkdepim/email.h>
00037 #include <libkpimidentities/identity.h>
00038 #include <libkpimidentities/identitymanager.h>
00039 #include "kmmainwin.h"
00040 #include "kmcomposewin.h"
00041 
00042 #include <mimelib/enum.h>
00043 
00044 #include <kinputdialog.h>
00045 #include <klocale.h>
00046 #include <kdebug.h>
00047 
00048 using namespace KMail;
00049 
00050 
00051 Callback::Callback( KMMessage* msg ) : mMsg( msg ),  mReceiverSet( false )
00052 {
00053 }
00054 
00055 bool Callback::mailICal( const QString& to, const QString iCal,
00056                          const QString& subject ) const
00057 {
00058   kdDebug(5006) << "Mailing message:\n" << iCal << endl;
00059 
00060   KMMessage *msg = new KMMessage;
00061   msg->initHeader();
00062   msg->setHeaderField( "Content-Type",
00063                        "text/calendar; method=reply; charset=\"utf-8\"" );
00064   msg->setSubject( subject );
00065   msg->setTo( to );
00066   msg->setBody( iCal.utf8() );
00067   msg->setFrom( receiver() );
00068   /* We want the triggering mail to be moved to the trash once this one
00069    * has been sent successfully. Set a link header which accomplishes that. */
00070   msg->link( mMsg, KMMsgStatusDeleted );
00071 
00072   // Outlook will only understand the reply if the From: header is the
00073   // same as the To: header of the invitation message.
00074   KConfigGroup options( KMKernel::config(), "Groupware" );
00075   if( !options.readBoolEntry( "LegacyMangleFromToHeaders", true ) ) {
00076     // Try and match the receiver with an identity
00077     const KPIM::Identity& identity =
00078       kmkernel->identityManager()->identityForAddress( receiver() );
00079     if( identity != KPIM::Identity::null )
00080       // Identity found. Use this
00081       msg->setFrom( identity.fullEmailAddr() );
00082       msg->setHeaderField("X-KMail-Identity", QString::number( identity.uoid() ));
00083       // Remove BCC from identity on ical invitations (https://intevation.de/roundup/kolab/issue474)
00084       msg->setBcc( "" );
00085   }
00086 
00087   KMComposeWin *cWin = new KMComposeWin();
00088   cWin->setMsg( msg, false /* mayAutoSign */ );
00089   // cWin->setCharset( "", true );
00090   cWin->slotWordWrapToggled( false );
00091   cWin->setSigningAndEncryptionDisabled( true );
00092 
00093   if ( options.readBoolEntry( "AutomaticSending", true ) ) {
00094     cWin->setAutoDeleteWindow(  true );
00095     cWin->slotSendNow();
00096   } else {
00097     cWin->show();
00098   }
00099 
00100   return true;
00101 }
00102 
00103 QString Callback::receiver() const
00104 {
00105   if ( mReceiverSet )
00106     // Already figured this out
00107     return mReceiver;
00108 
00109   mReceiverSet = true;
00110 
00111   QStringList addrs = KPIM::splitEmailAddrList( mMsg->to() );
00112   if( addrs.count() < 2 )
00113     // Only one receiver, so that has to be us
00114     mReceiver = mMsg->to();
00115   else {
00116     int found = 0;
00117     for( QStringList::Iterator it = addrs.begin(); it != addrs.end(); ++it ) {
00118       if( kmkernel->identityManager()->identityForAddress( *it ) !=
00119           KPIM::Identity::null ) {
00120         // Ok, this could be us
00121         ++found;
00122         mReceiver = *it;
00123       }
00124     }
00125 
00126     if( found != 1 ) {
00127       bool ok;
00128       mReceiver =
00129         KInputDialog::getItem( i18n( "Select Address" ),
00130                                i18n( "<qt>None of your identities match the "
00131                                      "receiver of this message,<br>please "
00132                                      "choose which of the following addresses "
00133                                      "is yours:" ),
00134                                addrs, 0, FALSE, &ok, kmkernel->mainWin() );
00135       if( !ok )
00136         mReceiver = QString::null;
00137     }
00138   }
00139 
00140   return mReceiver;
00141 }
00142 
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 22:43:37 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003