2
Copyright (c) 2007 Volker Krause <vkrause@kde.org>
4
This library is free software; you can redistribute it and/or modify it
5
under the terms of the GNU Library General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or (at your
7
option) any later version.
9
This library is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12
License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to the
16
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
#include "messagecopyhelper.h"
22
#include "kmcommands.h"
24
#include "kmmsgdict.h"
26
using namespace KMail;
29
MessageCopyHelper::MessageCopyHelper( const QList<quint32> & msgs,
30
KMFolder * dest, bool move, QObject * parent ) :
33
if ( msgs.isEmpty() || !dest )
38
QList<KMMsgBase*> list;
40
for ( QList<quint32>::ConstIterator it = msgs.constBegin(); it != msgs.constEnd(); ++it ) {
41
KMMsgDict::instance()->getLocation( *it, &f, &index );
42
if ( !f ) // not found
45
continue; // already there
46
if ( !mOpenFolders.contains( f ) ) {// not yet opened
47
f->open( "messagecopy" );
48
mOpenFolders.insert( f, 0 );
50
KMMsgBase *msgBase = f->getMsgBase( index );
52
list.append( msgBase );
56
return; // nothing to do
60
command = new KMMoveCommand( dest, list );
62
command = new KMCopyCommand( dest, list );
65
connect( command, SIGNAL(completed(KMCommand*)), SLOT(copyCompleted(KMCommand*)) );
69
void MessageCopyHelper::copyCompleted(KMCommand * cmd)
73
// close all folders we opened
74
for ( QMap<QPointer<KMFolder>, int>::ConstIterator it = mOpenFolders.constBegin();
75
it != mOpenFolders.constEnd(); ++it ) {
76
it.key()->close( "messagecopy" );
82
QList<quint32> MessageCopyHelper::serNumListFromMailList(const KPIM::MailList & list)
85
for ( MailList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it )
86
rv.append( (*it).serialNumber() );
90
QList<quint32> MessageCopyHelper::serNumListFromMsgList(QList<KMMsgBase*> list)
93
foreach ( KMMsgBase *msg, list )
95
rv.append( msg->getMsgSerNum() );
99
bool MessageCopyHelper::inReadOnlyFolder(const QList< quint32 > & sernums)
103
for ( QList<quint32>::ConstIterator it = sernums.begin(); it != sernums.end(); ++it ) {
104
KMMsgDict::instance()->getLocation( *it, &f, &index );
105
if ( !f ) // not found
107
if ( f->isReadOnly() )
113
KMFolder * MessageCopyHelper::firstSourceFolder( const QList<quint32> &sernums )
117
for ( QList<quint32>::ConstIterator it = sernums.begin(); it != sernums.end(); ++it ) {
118
KMMsgDict::instance()->getLocation( *it, &f, &index );
119
if ( !f ) // not found
127
#include "messagecopyhelper.moc"