Logo Search packages:      
Sourcecode: mailody version File versions  Download package

messagedata.h

/* This file is part of the KDE project

   Copyright (C) 2006-2007 KovoKs <info@kovoks.nl>
   Copyright (C) 2007 Frode M. Døving <frode@lnix.net>

   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.
*/


#ifndef MESSAGEDATA_H
#define MESSAGEDATA_H

#include <qobject.h>
#include <qdatetime.h>
#include <qstringlist.h>

#include <kglobal.h>
#include <klocale.h>
#include <kio/job.h>

class QStrList;
class QListViewItem;

namespace Mailody {

class ImapManager;

/**
 * @class MessageData
 * This is the main class which holds a message. It will disect the message
 * and fill the variables.
 * @author Tom Albers <tomalbers@kde.nl>
 */
00046 class MessageData : public QObject
{
    Q_OBJECT

  public:
    /**
     * Contructor. After construction the basic info to create a header
     * list is created. The other member variables will only be filled
     * after a request for the body is made.
     * @param parent parent widget
     * @param name give it a name
     * @param uid the uid of the message
     * @param mb the mailbox of the message
     */
    explicit MessageData( QWidget* parent,  const char* name,
                 int uid, const QString& mb );

    /**
     * Constructor. Similar to above. When you have the headers, you
     * can use this constructor. This saves a roundtrip to the database/
     * @param parent parent widget
     * @param name give it a name
     * @param uid the uid of the message
     * @param mb the mailbox of the message
     * @param headers the headers of the message
     */
    explicit MessageData( QWidget* parent,  const char* name,
                 int uid, const QString& mb, const QString& headers);

    /**
     * Destructor. As there can be multiple classes using this data,
     * please call done(), instead of deleting this object. See more
     * info at Done() and setBlocked().
     */
    ~MessageData();

    enum bodyType {
        Plain = 0,
        HTML,
        Source
    };

    /** Returns the mailbox */
00089     QString mb() const              { return m_mb;  }

    /**
     * Returns the subject of the message, also triggers the initialisation
     * of the rest of the headers.
     */
    QString subject();

    /** Returns the email address of the sender */
00098     QString sender_email() const    { return m_sender_email;   }

    /** Returns the name of the sender*/
00101     QString sender() const          { return m_sender;   }

    /** Returns the to header of the message, all recepients */
00104     QString to() const              { return m_to;   }

    /** Returns the size of message */
00107     int size() const                { return m_size;   }

    /** Returns the size of message for the user */
00110     QString vSize() const           { return
                        KIO::convertSize(KIO::filesize_t(m_size));   }

    /** Returns id of the message where this is a reply to */
00114     QString inreplyto() const       { return m_inreplyto;   }

    /** Returns the cc header of the message, all recepients */
00117     QString cc() const              { return m_cc;   }

    /**
     * Returns a list of the attachments, attached to the message
     * in the form path,name
     */
00123     QMap<QString,QString> attachments() const { return m_attachments;   }

    /** Returns all headers of the message */
00126     QString headers() const         { return m_headers;  }

    /** Returns the body of the message, this is only filled after the
        messageData() signal is emitted. This will be emitted when
        you have called requestBody(). See also raw() */
00131     QString body() const            { return m_body;  }

    /** Returns the original message, this is only filled after the
        messageData() signal is emitted. This will be emitted when
        you have called requestBody(). See also raw() and body() */
00136     QString originalBody() const    { return m_realraw;  }

    /** Returns the used userAgent of the message */
00139     QString userAgent() const       { return m_userAgent;  }

    /** Returns the messageID of the message */
00142     QString messageID() const       { return m_messageID;  }

    /** Returns the replyTo of the message */
00145     QString replyTo() const         { return m_replyTo;  }

    /** Returns the resent from of the message (redirected messages) */
00148     QString resentFrom() const      { return m_resentFrom;  }

    /** Returns the resent to of the message (redirected messages) */
00151     QString resentTo() const        { return m_resentTo;  }

    /** Returns the raw version of the message. You can call this to
        get the version of the message, which you can use to print
        for example. It will always return the plain version if possible */
00156     QString raw() const             { return m_raw; }

    /** Returns the DataTime of the message */
00159     QDateTime date() const          { return m_date;  }

    /** Returns the uid of the message */
00162     int uid() const                 { return m_uid; }

    /** Returns a list of the to addresses. See also to() */
00165     QStringList* to_list() const    { return m_to_addresses;   }

    /** Returns a list of the cc addresses. See also cc() */
00168     QStringList* cc_list() const    { return m_cc_addresses;   }

    /** Returns a QString with the date, which you can use to
        present to the user, quite expensive call, so be carefull */
    QString vDate() const;

    /**
     * Returns the name of the sender, including the emailaddress
     * @param i include the company if provided
     */
00178     QString sender_full(bool i)  {
        return i && !m_company.isEmpty() ? m_sender_full+" ("+m_company+")"
                : m_sender_full;   }

    /**
     * Return the contents of X-Mailody-Signature. (XMS)
     * This header is added when one saves the message
     * it is used when replacing the signature inside the composer 
     * on re-edit. Not included in sent messages.
     */
00188     QString getXMS()        { return m_xms; }

    /** Return the contents of X-Mailody-SP. (XMSP)
     * that is the signature placement int.
     */
00193     int getXMSP()           {return m_xmsp; }

    /** Returns if this message is deleted */
    bool isDeleted() const;

    /**
     * Returns if this message is read (not really New, it can be old but
     * unread.
    */
    bool isNew() const;

    /**
     * Returns if a user label has been set for this message.
     * @param i the type of the label, we support 0-5, where 0 is none.
     */
    bool hasUserTag( int i) const;

    /**
     * here you request the body. This will query the database or the imap
     * server for the body and will fill the variabeles, which you can
     * query with body() or raw(), but also most of the functions in this
     * class will only work after the body has been requested. Connect to
     * messageData() signal to know when the body is ready.
     */
    void requestBody( bodyType );

    /**
     * the sort date. see for more info the setSortDate() method
     */
00222     QDateTime sortDate() const {return m_sortDate;};

    /**
     * Here you can set the sort date. This date will be used when
     * sorting on date is performed. In our case, you can set this date
     * to the date of the youngest child for example. This is independent
     * of the shown date.
     */
00230     void setSortDate(QDateTime t) {m_sortDate = t; };

    /**
     * Here you can indicate that you dont want this data to be deleted. When
     * done() has been called before and @p block is false, this object will
     * be deleted.
     */
    void setBlocked( bool block );

    /**
     * This will delete this object, unless setBlocked() is called with true.
     * when that is the case, the object will only be deleted after a
     * setBlocked call with parameter false.
     */
    void done();

  private:
    bool        m_block;
    bool        m_delete;
    bool        m_initialized_all;
    ImapManager* m_datamanager;
    QString     m_subject;
    QString     m_sender;
    QString     m_sender_email;
    QString     m_sender_full;
    QString     m_company;
    QString     m_cc;
    int         m_size;
    QString     m_inreplyto;
    QStringList* m_cc_addresses;
    QString     m_to;
    QStringList* m_to_addresses;
    QMap<QString,QString> m_attachments;
    QString     m_headers;
    QString     m_body;
    QDateTime   m_date;
    QDateTime   m_sortDate;
    QString     m_vDate;
    QString     m_userAgent;
    QString     m_messageID;
    QString     m_replyTo;
    QString     m_resentFrom;
    QString     m_resentTo;

    QString     m_raw;
    QString     m_realraw;
    bodyType    m_bodyType;

    int         m_uid;
    int         m_xmsp;
    QString     m_mb;
    QStringList m_flags;
    QString     m_xms;

    void initialise_needed();
    void initialise_rest();
    void parseEmail(QString& email);
    QString highlightParagraph( const QString& text);

  private slots:
      void slotBodyReady(const QString&, int, const QString&);

  signals:
    /**
     * Emitted when the message is ready, for your convenience, the
     * MessageData (this) is send with the signal.
     */
    void messageData(const MessageData*);

    /**
     * Emitted when there is an attachment in the message.
     */
    void addContent(const MessageData*, const QString&, const QString&);
};

}

#endif


Generated by  Doxygen 1.6.0   Back to index