KIMAP Library
appendjob.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "appendjob.h"
00021
00022 #include <KDE/KLocale>
00023
00024 #include "job_p.h"
00025 #include "message_p.h"
00026 #include "session_p.h"
00027 #include "rfccodecs.h"
00028
00029 namespace KIMAP
00030 {
00031 class AppendJobPrivate : public JobPrivate
00032 {
00033 public:
00034 AppendJobPrivate( Session *session, const QString& name ) : JobPrivate( session, name ), uid( 0 ) { }
00035 ~AppendJobPrivate() { }
00036
00037 QString mailBox;
00038 QList<QByteArray> flags;
00039 QByteArray content;
00040 qint64 uid;
00041 };
00042 }
00043
00044 using namespace KIMAP;
00045
00046 AppendJob::AppendJob( Session *session )
00047 : Job( *new AppendJobPrivate(session, i18n("Append")) )
00048 {
00049 }
00050
00051 AppendJob::~AppendJob()
00052 {
00053 }
00054
00055 void AppendJob::setMailBox( const QString &mailBox )
00056 {
00057 Q_D(AppendJob);
00058 d->mailBox = mailBox;
00059 }
00060
00061 QString AppendJob::mailBox() const
00062 {
00063 Q_D(const AppendJob);
00064 return d->mailBox;
00065 }
00066
00067 void AppendJob::setFlags( const QList<QByteArray> &flags)
00068 {
00069 Q_D(AppendJob);
00070 d->flags = flags;
00071 }
00072
00073 QList<QByteArray> AppendJob::flags() const
00074 {
00075 Q_D(const AppendJob);
00076 return d->flags;
00077 }
00078
00079 void AppendJob::setContent( const QByteArray &content )
00080 {
00081 Q_D(AppendJob);
00082 d->content = content;
00083 }
00084
00085 QByteArray AppendJob::content() const
00086 {
00087 Q_D(const AppendJob);
00088 return d->content;
00089 }
00090
00091 qint64 AppendJob::uid() const
00092 {
00093 Q_D(const AppendJob);
00094 return d->uid;
00095 }
00096
00097 void AppendJob::doStart()
00098 {
00099 Q_D(AppendJob);
00100
00101 QByteArray parameters = '\"'+KIMAP::encodeImapFolderName( d->mailBox.toUtf8() )+'\"';
00102
00103 if ( !d->flags.isEmpty() ) {
00104 parameters+=" (";
00105 foreach ( const QByteArray &flag, d->flags ) {
00106 parameters+= flag+' ';
00107 }
00108 parameters.chop(1);
00109 parameters+=')';
00110 }
00111
00112 parameters+=" {"+QByteArray::number(d->content.size())+'}';
00113 qDebug("%s", parameters.constData());
00114
00115 d->tag = d->sessionInternal()->sendCommand( "APPEND", parameters );
00116 }
00117
00118 void AppendJob::handleResponse( const Message &response )
00119 {
00120 Q_D(AppendJob);
00121
00122 for ( QList<Message::Part>::ConstIterator it = response.responseCode.begin();
00123 it != response.responseCode.end(); ++it ) {
00124 if ( it->toString()=="APPENDUID" ) {
00125 it = it + 2;
00126 if ( it != response.responseCode.end() ) {
00127 d->uid = it->toString().toLongLong();
00128 }
00129 break;
00130 }
00131 }
00132
00133 if (handleErrorReplies(response) == NotHandled ) {
00134 if ( response.content[0].toString() == "+" ) {
00135 d->sessionInternal()->sendData( d->content );
00136 }
00137 }
00138 }
00139
00140 #include "appendjob.moc"