• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kmobiletools

akonadi_serializer_sms.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (c) 2007 Till Adam <adam@kde.org>
00003     Copyright (c) 2007 Marco Gulino <marco@kmobiletools.org> (adapted to kmobiletools)
00004 
00005     This library is free software; you can redistribute it and/or modify it
00006     under the terms of the GNU Library General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or (at your
00008     option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful, but WITHOUT
00011     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013     License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to the
00017     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00018     02110-1301, USA.
00019 */
00020 
00021 #include "akonadi_serializer_sms.h"
00022 
00023 #include <kdebug.h>
00024 #include <libkmobiletools/sms.h>
00025 #include <boost/shared_ptr.hpp>
00026 
00027 #include <akonadi/item.h>
00028 #include <akonadi/private/imapparser_p.h> //FIXME: Do it right without internal class!
00029 
00030 #define SMS_MIMETYPE "application/x-kmobiletools-sms"
00031 
00032 using namespace Akonadi;
00033 using namespace KMime;
00034 
00035 typedef boost::shared_ptr<KMobileTools::SMS> MessagePtr;
00036 
00037 template <typename T> static void parseAddrList( const QList<QByteArray> &addrList, T *hdr )
00038 {
00039   for ( QList<QByteArray>::ConstIterator it = addrList.constBegin(); it != addrList.constEnd(); ++it ) {
00040     QList<QByteArray> addr;
00041     ImapParser::parseParenthesizedList( *it, addr );
00042     if ( addr.count() != 4 ) {
00043       qWarning() << "Error parsing envelope address field: " << addr;
00044       continue;
00045     }
00046     KMime::Types::Mailbox addrField;
00047     addrField.setNameFrom7Bit( addr[0] );
00048     addrField.setAddress( addr[2] + '@' + addr[3] );
00049     hdr->addAddress( addrField );
00050   }
00051 }
00052 
00053 
00054 bool SerializerPluginSMS::deserialize( Item& item, const QByteArray& label, QIODevice& data, int version )
00055 {
00056     Q_UNUSED( version );
00057 
00058     kDebug() <<"()" << label;
00059     if ( label != "SMS" ) {
00060       return false;
00061     }
00062 
00063     MessagePtr msg;
00064     if ( !item.hasPayload() ) {
00065         KMobileTools::SMS *m = new  KMobileTools::SMS();
00066         msg = MessagePtr( m );
00067         item.setPayload( msg );
00068     } else {
00069         msg = item.payload<MessagePtr>();
00070     }
00071 
00072     if ( label == "SMS" ) {
00073         msg->setContent( data.readAll() );
00074         msg->parse();
00075     }/*
00076     else if ( label == "ENVELOPE" ) {
00077         QList<QByteArray> env;
00078         ImapParser::parseParenthesizedList( data, env );
00079         Q_ASSERT( env.count() >= 10 );
00080         // date
00081         msg->date()->from7BitString( env[0] );
00082         // subject
00084         // from
00085         QList<QByteArray> addrList;
00086         ImapParser::parseParenthesizedList( env[2], addrList );
00089         // sender
00090         // not supported by kmime, skip it
00091         // reply-to
00092         ImapParser::parseParenthesizedList( env[4], addrList );
00095         // to
00096         ImapParser::parseParenthesizedList( env[5], addrList );
00099         // cc
00100         ImapParser::parseParenthesizedList( env[6], addrList );
00103         // bcc
00104         ImapParser::parseParenthesizedList( env[7], addrList );
00107         // in-reply-to
00109         // message id
00111     }*/
00112 
00113     return true;
00114 }
00115 
00116 
00117 void SerializerPluginSMS::serialize( const Item& item, const QByteArray& label, QIODevice& data, int &version )
00118 {
00119     Q_UNUSED( version );
00120 
00121     kDebug() <<"()" << label;
00122     if ( label != "SMS" )
00123       return;
00124 
00125     boost::shared_ptr<KMobileTools::SMS> m = item.payload< boost::shared_ptr<KMobileTools::SMS> >();
00126     m->assemble();
00127     data.write( m->encodedContent() );
00128 }
00129 
00130 
00131 extern "C"
00132 KDE_EXPORT Akonadi::ItemSerializerPlugin *
00133 akonadi_serializer_sms_create_item_serializer_plugin() {
00134   return new SerializerPluginSMS();
00135 }
00136 
00137 

kmobiletools

Skip menu "kmobiletools"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal