You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
409 lines
10 KiB
409 lines
10 KiB
15 years ago
|
/**********************************************************************
|
||
|
*
|
||
4 years ago
|
* imapcommand.cpp - IMAP4rev1 command handler
|
||
17 years ago
|
* Copyright (C) 2000 Sven Carstens <s.carstens@gmx.de>
|
||
15 years ago
|
*
|
||
|
* This program is free software; you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation; either version 2 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
*
|
||
|
* Send comments and bug fixes to s.carstens@gmx.de
|
||
|
*
|
||
|
*********************************************************************/
|
||
|
|
||
|
#include "imapcommand.h"
|
||
|
#include "rfcdecoder.h"
|
||
|
|
||
|
/*#include <stdlib.h>
|
||
|
|
||
|
#include <sys/types.h>
|
||
|
#include <sys/socket.h>
|
||
|
#include <sys/wait.h>
|
||
|
#include <sys/stat.h>
|
||
|
|
||
|
#include <fcntl.h>
|
||
|
|
||
|
#include <netinet/in.h>
|
||
|
#include <arpa/inet.h>
|
||
|
|
||
|
#include <errno.h>
|
||
|
#include <signal.h>
|
||
|
#include <stdio.h>
|
||
|
#include <netdb.h>
|
||
|
#include <unistd.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
15 years ago
|
#include <tqregexp.h>
|
||
|
#include <tqbuffer.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdeprotocolmanager.h>
|
||
15 years ago
|
#include <ksock.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <kinstance.h>
|
||
12 years ago
|
#include <tdeio/connection.h>
|
||
|
#include <tdeio/slaveinterface.h>
|
||
|
#include <tdeio/passdlg.h>
|
||
12 years ago
|
#include <tdelocale.h> */
|
||
15 years ago
|
|
||
|
imapCommand::imapCommand ()
|
||
|
{
|
||
|
mComplete = false;
|
||
14 years ago
|
mId = TQString();
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
imapCommand::imapCommand (const TQString & command, const TQString & parameter)
|
||
15 years ago
|
// aCommand(NULL),
|
||
|
// mResult(NULL),
|
||
|
// mParameter(NULL)
|
||
|
{
|
||
|
mComplete = false;
|
||
|
aCommand = command;
|
||
|
aParameter = parameter;
|
||
14 years ago
|
mId = TQString();
|
||
15 years ago
|
}
|
||
|
|
||
|
bool
|
||
|
imapCommand::isComplete ()
|
||
|
{
|
||
|
return mComplete;
|
||
|
}
|
||
|
|
||
15 years ago
|
const TQString &
|
||
15 years ago
|
imapCommand::result ()
|
||
|
{
|
||
|
return mResult;
|
||
|
}
|
||
|
|
||
15 years ago
|
const TQString &
|
||
15 years ago
|
imapCommand::resultInfo ()
|
||
|
{
|
||
|
return mResultInfo;
|
||
|
}
|
||
|
|
||
15 years ago
|
const TQString &
|
||
15 years ago
|
imapCommand::id ()
|
||
|
{
|
||
|
return mId;
|
||
|
}
|
||
|
|
||
15 years ago
|
const TQString &
|
||
15 years ago
|
imapCommand::parameter ()
|
||
|
{
|
||
|
return aParameter;
|
||
|
}
|
||
|
|
||
15 years ago
|
const TQString &
|
||
15 years ago
|
imapCommand::command ()
|
||
|
{
|
||
|
return aCommand;
|
||
|
}
|
||
|
|
||
|
void
|
||
15 years ago
|
imapCommand::setId (const TQString & id)
|
||
15 years ago
|
{
|
||
|
if (mId.isEmpty ())
|
||
|
mId = id;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
imapCommand::setComplete ()
|
||
|
{
|
||
|
mComplete = true;
|
||
|
}
|
||
|
|
||
|
void
|
||
15 years ago
|
imapCommand::setResult (const TQString & result)
|
||
15 years ago
|
{
|
||
|
mResult = result;
|
||
|
}
|
||
|
|
||
|
void
|
||
15 years ago
|
imapCommand::setResultInfo (const TQString & result)
|
||
15 years ago
|
{
|
||
|
mResultInfo = result;
|
||
|
}
|
||
|
|
||
|
void
|
||
15 years ago
|
imapCommand::setCommand (const TQString & command)
|
||
15 years ago
|
{
|
||
|
aCommand = command;
|
||
|
}
|
||
|
|
||
|
void
|
||
15 years ago
|
imapCommand::setParameter (const TQString & parameter)
|
||
15 years ago
|
{
|
||
|
aParameter = parameter;
|
||
|
}
|
||
|
|
||
14 years ago
|
const TQString
|
||
15 years ago
|
imapCommand::getStr ()
|
||
|
{
|
||
|
if (parameter().isEmpty())
|
||
|
return id() + " " + command() + "\r\n";
|
||
|
else
|
||
|
return id() + " " + command() + " " + parameter() + "\r\n";
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
|
imapCommand::clientNoop ()
|
||
|
{
|
||
|
return new imapCommand ("NOOP", "");
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientFetch (ulong uid, const TQString & fields, bool nouid)
|
||
15 years ago
|
{
|
||
|
return clientFetch (uid, uid, fields, nouid);
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientFetch (ulong fromUid, ulong toUid, const TQString & fields,
|
||
15 years ago
|
bool nouid)
|
||
|
{
|
||
15 years ago
|
TQString uid = TQString::number(fromUid);
|
||
15 years ago
|
|
||
|
if (fromUid != toUid)
|
||
|
{
|
||
|
uid += ":";
|
||
|
if (toUid < fromUid)
|
||
|
uid += "*";
|
||
|
else
|
||
15 years ago
|
uid += TQString::number(toUid);
|
||
15 years ago
|
}
|
||
|
return clientFetch (uid, fields, nouid);
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientFetch (const TQString & sequence, const TQString & fields,
|
||
15 years ago
|
bool nouid)
|
||
|
{
|
||
|
return new imapCommand (nouid ? "FETCH" : "UID FETCH",
|
||
|
sequence + " (" + fields + ")");
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientList (const TQString & reference, const TQString & path,
|
||
15 years ago
|
bool lsub)
|
||
|
{
|
||
|
return new imapCommand (lsub ? "LSUB" : "LIST",
|
||
15 years ago
|
TQString ("\"") + rfcDecoder::toIMAP (reference) +
|
||
15 years ago
|
"\" \"" + rfcDecoder::toIMAP (path) + "\"");
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientSelect (const TQString & path, bool examine)
|
||
15 years ago
|
{
|
||
|
Q_UNUSED(examine);
|
||
|
/** @note We use always SELECT, because UW-IMAP doesn't check for new mail, when
|
||
|
used with the "mbox driver" and the folder is opened with EXAMINE
|
||
|
and Courier can't append to a mailbox that is in EXAMINE state */
|
||
|
return new imapCommand ("SELECT",
|
||
15 years ago
|
TQString ("\"") + rfcDecoder::toIMAP (path) + "\"");
|
||
15 years ago
|
}
|
||
|
|
||
|
imapCommand *
|
||
|
imapCommand::clientClose()
|
||
|
{
|
||
|
return new imapCommand("CLOSE", "");
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientCopy (const TQString & box, const TQString & sequence,
|
||
15 years ago
|
bool nouid)
|
||
|
{
|
||
|
return new imapCommand (nouid ? "COPY" : "UID COPY",
|
||
|
sequence + " \"" + rfcDecoder::toIMAP (box) + "\"");
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientAppend (const TQString & box, const TQString & flags,
|
||
15 years ago
|
ulong size)
|
||
|
{
|
||
|
return new imapCommand ("APPEND",
|
||
|
"\"" + rfcDecoder::toIMAP (box) + "\" " +
|
||
|
((flags.isEmpty()) ? "" : ("(" + flags + ") ")) +
|
||
15 years ago
|
"{" + TQString::number(size) + "}");
|
||
15 years ago
|
}
|
||
|
|
||
|
imapCommand *
|
||
13 years ago
|
imapCommand::clienStatus (const TQString & path, const TQString & parameters)
|
||
15 years ago
|
{
|
||
|
return new imapCommand ("STATUS",
|
||
15 years ago
|
TQString ("\"") + rfcDecoder::toIMAP (path) +
|
||
15 years ago
|
"\" (" + parameters + ")");
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientCreate (const TQString & path)
|
||
15 years ago
|
{
|
||
|
return new imapCommand ("CREATE",
|
||
15 years ago
|
TQString ("\"") + rfcDecoder::toIMAP (path) + "\"");
|
||
15 years ago
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientDelete (const TQString & path)
|
||
15 years ago
|
{
|
||
|
return new imapCommand ("DELETE",
|
||
15 years ago
|
TQString ("\"") + rfcDecoder::toIMAP (path) + "\"");
|
||
15 years ago
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientSubscribe (const TQString & path)
|
||
15 years ago
|
{
|
||
|
return new imapCommand ("SUBSCRIBE",
|
||
15 years ago
|
TQString ("\"") + rfcDecoder::toIMAP (path) + "\"");
|
||
15 years ago
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientUnsubscribe (const TQString & path)
|
||
15 years ago
|
{
|
||
|
return new imapCommand ("UNSUBSCRIBE",
|
||
15 years ago
|
TQString ("\"") + rfcDecoder::toIMAP (path) + "\"");
|
||
15 years ago
|
}
|
||
|
|
||
|
imapCommand *
|
||
|
imapCommand::clientExpunge ()
|
||
|
{
|
||
15 years ago
|
return new imapCommand ("EXPUNGE", TQString (""));
|
||
15 years ago
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientRename (const TQString & src, const TQString & dest)
|
||
15 years ago
|
{
|
||
|
return new imapCommand ("RENAME",
|
||
15 years ago
|
TQString ("\"") + rfcDecoder::toIMAP (src) +
|
||
15 years ago
|
"\" \"" + rfcDecoder::toIMAP (dest) + "\"");
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientSearch (const TQString & search, bool nouid)
|
||
15 years ago
|
{
|
||
|
return new imapCommand (nouid ? "SEARCH" : "UID SEARCH", search);
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientStore (const TQString & set, const TQString & item,
|
||
|
const TQString & data, bool nouid)
|
||
15 years ago
|
{
|
||
|
return new imapCommand (nouid ? "STORE" : "UID STORE",
|
||
|
set + " " + item + " (" + data + ")");
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
|
imapCommand::clientLogout ()
|
||
|
{
|
||
|
return new imapCommand ("LOGOUT", "");
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
|
imapCommand::clientStartTLS ()
|
||
|
{
|
||
|
return new imapCommand ("STARTTLS", "");
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientSetACL( const TQString& box, const TQString& user, const TQString& acl )
|
||
15 years ago
|
{
|
||
15 years ago
|
return new imapCommand ("SETACL", TQString("\"") + rfcDecoder::toIMAP (box)
|
||
15 years ago
|
+ "\" \"" + rfcDecoder::toIMAP (user)
|
||
|
+ "\" \"" + rfcDecoder::toIMAP (acl) + "\"");
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientDeleteACL( const TQString& box, const TQString& user )
|
||
15 years ago
|
{
|
||
15 years ago
|
return new imapCommand ("DELETEACL", TQString("\"") + rfcDecoder::toIMAP (box)
|
||
15 years ago
|
+ "\" \"" + rfcDecoder::toIMAP (user)
|
||
|
+ "\"");
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientGetACL( const TQString& box )
|
||
15 years ago
|
{
|
||
15 years ago
|
return new imapCommand ("GETACL", TQString("\"") + rfcDecoder::toIMAP (box)
|
||
15 years ago
|
+ "\"");
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientListRights( const TQString& box, const TQString& user )
|
||
15 years ago
|
{
|
||
15 years ago
|
return new imapCommand ("LISTRIGHTS", TQString("\"") + rfcDecoder::toIMAP (box)
|
||
15 years ago
|
+ "\" \"" + rfcDecoder::toIMAP (user)
|
||
|
+ "\"");
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientMyRights( const TQString& box )
|
||
15 years ago
|
{
|
||
15 years ago
|
return new imapCommand ("MYRIGHTS", TQString("\"") + rfcDecoder::toIMAP (box)
|
||
15 years ago
|
+ "\"");
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientSetAnnotation( const TQString& box, const TQString& entry, const TQMap<TQString, TQString>& attributes )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString parameter = TQString("\"") + rfcDecoder::toIMAP (box)
|
||
15 years ago
|
+ "\" \"" + rfcDecoder::toIMAP (entry)
|
||
|
+ "\" (";
|
||
15 years ago
|
for( TQMap<TQString,TQString>::ConstIterator it = attributes.begin(); it != attributes.end(); ++it ) {
|
||
15 years ago
|
parameter += "\"";
|
||
|
parameter += rfcDecoder::toIMAP (it.key());
|
||
|
parameter += "\" \"";
|
||
|
parameter += rfcDecoder::toIMAP (it.data());
|
||
|
parameter += "\" ";
|
||
|
}
|
||
|
// Turn last space into a ')'
|
||
|
parameter[parameter.length()-1] = ')';
|
||
|
|
||
|
return new imapCommand ("SETANNOTATION", parameter);
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientGetAnnotation( const TQString& box, const TQString& entry, const TQStringList& attributeNames )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString parameter = TQString("\"") + rfcDecoder::toIMAP (box)
|
||
15 years ago
|
+ "\" \"" + rfcDecoder::toIMAP (entry)
|
||
|
+ "\" ";
|
||
|
if ( attributeNames.count() == 1 )
|
||
|
parameter += "\"" + rfcDecoder::toIMAP (attributeNames.first()) + '"';
|
||
|
else {
|
||
|
parameter += '(';
|
||
15 years ago
|
for( TQStringList::ConstIterator it = attributeNames.begin(); it != attributeNames.end(); ++it ) {
|
||
15 years ago
|
parameter += "\"" + rfcDecoder::toIMAP (*it) + "\" ";
|
||
|
}
|
||
|
// Turn last space into a ')'
|
||
|
parameter[parameter.length()-1] = ')';
|
||
|
}
|
||
|
return new imapCommand ("GETANNOTATION", parameter);
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
|
imapCommand::clientNamespace()
|
||
|
{
|
||
|
return new imapCommand("NAMESPACE", "");
|
||
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientGetQuotaroot( const TQString& box )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString parameter = TQString("\"") + rfcDecoder::toIMAP (box) + '"';
|
||
13 years ago
|
return new imapCommand ("GETQUOTAROOT", parameter);
|
||
15 years ago
|
}
|
||
|
|
||
|
imapCommand *
|
||
15 years ago
|
imapCommand::clientCustom( const TQString& command, const TQString& arguments )
|
||
15 years ago
|
{
|
||
|
return new imapCommand (command, arguments);
|
||
|
}
|
||
|
|