Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

mailwrapper.cpp

Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include <sys/stat.h>
00003 #include <sys/types.h>
00004 #include <unistd.h>
00005 #include <fcntl.h>
00006 #include <string.h>
00007 #include <qdir.h>
00008 
00009 #include "mailwrapper.h"
00010 //#include "logindialog.h"
00011 //#include "defines.h"
00012 
00013 #define UNDEFINED 64
00014 #define MAXLINE  76
00015 #define UTF16MASK       0x03FFUL
00016 #define UTF16SHIFT      10
00017 #define UTF16BASE       0x10000UL
00018 #define UTF16HIGHSTART  0xD800UL
00019 #define UTF16HIGHEND    0xDBFFUL
00020 #define UTF16LOSTART    0xDC00UL
00021 #define UTF16LOEND      0xDFFFUL
00022 
00023 
00024 using namespace Opie::Core;
00025 Attachment::Attachment( DocLnk lnk )
00026 {
00027     doc = lnk;
00028     size = QFileInfo( doc.file() ).size();
00029 }
00030 
00031 Folder::Folder(const QString&tmp_name, const QString&sep  )
00032 {
00033     name = tmp_name;
00034     nameDisplay = name;
00035     separator = sep;
00036     prefix = "";
00037 }
00038 
00039 Folder::~Folder()
00040 {
00041 }
00042 
00043 const QString& Folder::Separator()const
00044 {
00045     return separator;
00046 }
00047 
00048 IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&aprefix )
00049     : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf)
00050 {
00051   // Decode IMAP foldername
00052   nameDisplay = IMAPFolder::decodeFolderName( name );
00053   /*
00054   odebug << "folder " + name + " - displayed as " + nameDisplay << oendl; 
00055   */
00056     prefix = aprefix;
00057 
00058     if (prefix.length()>0) {
00059         if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) {
00060             nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length());
00061         }
00062     }
00063 }
00064 
00065 IMAPFolder::~IMAPFolder()
00066 {
00067 }
00068 
00069 static unsigned char base64chars[] =
00070   "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
00071 
00076 QString IMAPFolder::decodeFolderName( const QString &name )
00077 {
00078   unsigned char c, i, bitcount;
00079   unsigned long ucs4, utf16, bitbuf;
00080   unsigned char base64[256], utf8[6];
00081   unsigned long srcPtr = 0;
00082   QCString dst = "";
00083   QCString src = name.ascii();
00084 
00085   /* initialize modified base64 decoding table */
00086   memset(base64, UNDEFINED, sizeof(base64));
00087   for (i = 0; i < sizeof(base64chars); ++i) {
00088     base64[(int)base64chars[i]] = i;
00089   }
00090 
00091   /* loop until end of string */
00092   while (srcPtr < src.length ()) {
00093     c = src[srcPtr++];
00094     /* deal with literal characters and &- */
00095     if (c != '&' || src[srcPtr] == '-') {
00096       /* encode literally */
00097       dst += c;
00098       /* skip over the '-' if this is an &- sequence */
00099       if (c == '&')
00100         srcPtr++;
00101     } else {
00102       /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */
00103       bitbuf = 0;
00104       bitcount = 0;
00105       ucs4 = 0;
00106       while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) {
00107         ++srcPtr;
00108         bitbuf = (bitbuf << 6) | c;
00109         bitcount += 6;
00110         /* enough bits for a UTF-16 character? */
00111         if (bitcount >= 16) {
00112           bitcount -= 16;
00113           utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff;
00114           /* convert UTF16 to UCS4 */
00115           if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) {
00116             ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT;
00117             continue;
00118           } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) {
00119             ucs4 += utf16 - UTF16LOSTART + UTF16BASE;
00120           } else {
00121             ucs4 = utf16;
00122           }
00123           /* convert UTF-16 range of UCS4 to UTF-8 */
00124           if (ucs4 <= 0x7fUL) {
00125             utf8[0] = ucs4;
00126             i = 1;
00127           } else if (ucs4 <= 0x7ffUL) {
00128             utf8[0] = 0xc0 | (ucs4 >> 6);
00129             utf8[1] = 0x80 | (ucs4 & 0x3f);
00130             i = 2;
00131           } else if (ucs4 <= 0xffffUL) {
00132             utf8[0] = 0xe0 | (ucs4 >> 12);
00133             utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f);
00134             utf8[2] = 0x80 | (ucs4 & 0x3f);
00135             i = 3;
00136           } else {
00137             utf8[0] = 0xf0 | (ucs4 >> 18);
00138             utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f);
00139             utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f);
00140             utf8[3] = 0x80 | (ucs4 & 0x3f);
00141             i = 4;
00142           }
00143           /* copy it */
00144           for (c = 0; c < i; ++c) {
00145             dst += utf8[c];
00146           }
00147         }
00148       }
00149       /* skip over trailing '-' in modified UTF-7 encoding */
00150       if (src[srcPtr] == '-')
00151         ++srcPtr;
00152     }
00153   }
00154 
00155   return QString::fromUtf8( dst.data() );
00156 }
00157 
00158 Mail::Mail()
00159     :Opie::Core::ORefCount(),name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("")
00160 {
00161 }
00162 
00163 MHFolder::MHFolder(const QString&disp_name,const QString&mbox)
00164     : Folder( disp_name,"/" )
00165 {
00166     separator = "/";
00167     name = mbox;
00168     if (!disp_name.startsWith("/") && disp_name.length()>0)
00169         name+="/";
00170     name+=disp_name;
00171     if (disp_name.length()==0) {
00172         nameDisplay = separator;
00173     }
00174     prefix = mbox;
00175 }
00176 
00177 MHFolder::~MHFolder()
00178 {
00179 }

Generated on Sat Nov 5 16:17:38 2005 for OPIE by  doxygen 1.4.2