{"id":305,"date":"2011-09-30T16:13:44","date_gmt":"2011-09-30T16:13:44","guid":{"rendered":"http:\/\/www.michaelm.info\/blog\/?p=305"},"modified":"2011-09-30T16:13:44","modified_gmt":"2011-09-30T16:13:44","slug":"android-mail-app-and-imap-fail","status":"publish","type":"post","link":"http:\/\/www.michaelm.info\/blog\/?p=305","title":{"rendered":"Android mail app with IMAP == #FAIL"},"content":{"rendered":"<p>Well, I&#8217;m still vetting my HTC Sensation to see if it is a worthy replacement for my BlackBerry&#8230; Still not convinced as it happens. However, I have resolved one of my problems with it&#8230;<\/p>\n<p>IMAP sent\/trash\/draft folders don&#8217;t work properly if you have a &#8220;typical&#8221; IMAP server with a folder prefix of &#8220;INBOX.&#8221;. The IMAP NAMESPACE RFC (<a title=\"RFC2342\" href=\"http:\/\/www.ietf.org\/rfc\/rfc2342.txt\" target=\"_blank\">RFC2342<\/a>) defines how this works and how clients should handle it. As usual, Google developers figured they knew better than or just chose to ignore the RFC! As a result, the Andoird mail application doesn&#8217;t support folder prefixes, let alone automatically working correctly based on the namespace command.<\/p>\n<p>If you are lucky and are using a IMAP server which does not have a personal namespace (Dovecot??) you might find the mail app works OK for you.<\/p>\n<p>You can use the Android K9 mail client. I briefly tried it and it seemed to work. However, it doesn&#8217;t seem as &#8220;integrated&#8221; as the stock client so I gave up on it. It&#8217;s not a bad app &#8211; it just didn&#8217;t grab my attention. Luckily, there is a work around which is partially documented on the Android issues page at (thanks to those who posted there as it got me working on this workaround):<\/p>\n<p><a title=\"Android issue relating to IMAP namespace folders\" href=\"http:\/\/code.google.com\/p\/android\/issues\/detail?id=1811\" target=\"_blank\">http:\/\/code.google.com\/p\/android\/issues\/detail?id=1811<\/a> in particular <a title=\"comment 83\" href=\"http:\/\/code.google.com\/p\/android\/issues\/detail?id=1811#c83\" target=\"_blank\">comment 83<\/a> and <a title=\"comment 84\" href=\"http:\/\/code.google.com\/p\/android\/issues\/detail?id=1811#c84\" target=\"_blank\">comment 84<\/a>.<\/p>\n<p>The work around is to reconfigure the mail application&#8217;s SQLite database to point to IMAP provided folders rather than the default folders which do not work. On the surface it is pretty easy if your phone is rooted &#8211; no idea how I&#8217;d do this if the phone was not rooted.<\/p>\n<p>The method I used in the end, to get around the SQLite database files being in use, was to boot to clockworkmod-recovery, mount \/data, adb the necessary files to the PC, edit the datafiles using SQLite and push them back using ADB.<\/p>\n<p>The updating of the database is the trick. First, the ID of the account to be &#8220;fixed&#8221; needs to be determined. This account ID is then used to get a list of corresponding folders&#8217; IDs from the mailboxs [sic]. These IDs and names are then used to update the accounts table which is the &#8220;magic bit&#8221;.<\/p>\n<p>Here is the code snippet of the steps I followed. If you have a vague idea of technical stuff in this area, you should be able to follow the steps.<\/p>\n<p>**boot into clockworkmod recovery<br \/>\n** mount \/data on the phone<br \/>\n** connect USB cable to phone and PC and select HTC Sync mode<br \/>\n** check device can be seen by adb:<\/p>\n<pre>adb devices\n<\/pre>\n<p>** copy the data files from the phone to your PC (might not have the -shm and -wal files):<\/p>\n<pre>adb pull \/data\/data\/com.htc.android.mail\/databases\/mail.db\nadb pull \/data\/data\/com.htc.android.mail\/databases\/mail.db-shm\nadb pull \/data\/data\/com.htc.android.mail\/databases\/mail.db-wal<\/pre>\n<p>** run sqlite on the data files<\/p>\n<pre>sqlite3.exe mail.db\nsqlite&gt;\u00a0 pragma wal_checkpoint;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -- to clear the sqlite logfiles...\nsqlite&gt;\u00a0 pragma wal_checkpoint(FULL);      -- to clear the sqlite logfiles...\nsqlite&gt;\nsqlite&gt; .headers on\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -- to make it easier to see whats happening\nsqlite&gt; .mode column\u00a0\u00a0\u00a0\u00a0\u00a0 -- or .mode list\n\nsqlite&gt; --view the current folders for all accounts\nsqlite&gt; select _id, _name, _sentfolder, _sentfoldertext, _sentfolderid from accounts;\nsqlite&gt; select _id, _name, _trashfolder, _trashfoldertext, _trashfolderid from accounts;\nsqlite&gt; select _id, _name, _draftfolder, _draftfoldertext, _draftfolderid from accounts;<\/pre>\n<p>** based on output from above, determine the _id value for the account to modify (<span style=\"color: #ff0000;\">1<\/span> is used below in example):<\/p>\n<pre>sqlite&gt; select * from mailboxs where _account=<span style=\"color: #ff0000;\">1<\/span>;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 --where <span style=\"color: #ff0000;\">1<\/span> is from _ID above\nsqlite&gt; --below command is more succinct and useful...\nsqlite&gt; select _id,_undecodename,_decodename,_shortname from mailboxs where _account=<span style=\"color: #ff0000;\">1<\/span>;\u00a0\u00a0 --where <span style=\"color: #ff0000;\">1<\/span> is _ID above<\/pre>\n<p>** the above will give a list of folder IDs and corresponding names. Hopefully, the _undecodename, _decodename and _shortname fields are equal. If not, then I&#8217;m not sure which you&#8217;d use in the step below &#8211; some trial and error might be needed, but I&#8217;d start with the _decodename values.<\/p>\n<p>** if you have a large number of IMAP folders and a &#8220;typical&#8221; IMAP server, the following should list the three needed folders and their associated IDs:<\/p>\n<pre>sqlite&gt; select _id,_undecodename,_decodename,_shortname from mailboxs\n   ...&gt; where _account=<span style=\"color: #ff0000;\">1<\/span> and\n   ...&gt; _shortname in (\"INBOX.Drafts\",\"INBOX.Sent\",\"INBOX.Trash\");\n<\/pre>\n<p>** Once you have the folders&#8217; _id values you use them in the commands below, changing the _sentfolderid, _trashfolderid and _draftfolderid values to correspond with those shown in the above step. Note to change the where clause to reflect the correct account _id used above.<\/p>\n<pre>sqlite&gt; --update the folder details\nsqlite&gt; update accounts set _sentfolder = 'INBOX.Sent', _sentfoldertext = 'INBOX.Sent', _sentfolderid =<span style=\"color: #ff0000;\"> 23<\/span> where _id=<span style=\"color: #ff0000;\">1<\/span>;\nsqlite&gt; update accounts set _trashfolder = 'INBOX.Trash', _trashfoldertext = 'INBOX.Trash', _trashfolderid =<span style=\"color: #ff0000;\"> 9<\/span> where _id=<span style=\"color: #ff0000;\">1<\/span>;\nsqlite&gt; update accounts set _draftfolder = 'INBOX.Drafts', _draftfoldertext = 'INBOX.Drafts', _draftfolderid = <span style=\"color: #ff0000;\">27<\/span> where _id=<span style=\"color: #ff0000;\">1<\/span>;\n\nsqlite&gt; --exit from sqlite\nsqlite&gt; .quit\n<\/pre>\n<p>** back at your DOS prompt, delete the files on your phone (maybe mv instead for backup purposes?? &#8211; your choice) and push the updated files<\/p>\n<pre>adb shell rm \/data\/data\/com.htc.android.mail\/databases\/mail.db\nadb shell rm \/data\/data\/com.htc.android.mail\/databases\/mail.db-wal\nadb shell rm \/data\/data\/com.htc.android.mail\/databases\/mail.db-shm\nadb push mail.db \/data\/data\/com.htc.android.mail\/databases\/mail.db\nadb push mail.db-wal \/data\/data\/com.htc.android.mail\/databases\/mail.db-wal\nadb push mail.db-shm \/data\/data\/com.htc.android.mail\/databases\/mail.db-shm\n<\/pre>\n<p>**reboot the phone and hopefully all is working with the correct folders!!<\/p>\n<pre>adb reboot<\/pre>\n<p>&nbsp;<\/p>\n<p>Note: If your phone has sqlite3 installed on it and it is rooted, you may be able to issue the above sqlite commands without having to boot into recovery mode. I&#8217;m not sure how well the mail app would behave with it&#8217;s configuration changing while it is running.<\/p>\n<p>Note2: You do this at your own risk, etc etc. It worked for me. It might work for you &#8211; or it might not.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well, I&#8217;m still vetting my HTC Sensation to see if it is a worthy replacement for my BlackBerry&#8230; Still not convinced as it happens. However, I have resolved one of my problems with it&#8230; IMAP sent\/trash\/draft folders don&#8217;t work properly if you have a &#8220;typical&#8221; IMAP server with a folder prefix of &#8220;INBOX.&#8221;. The IMAP [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[21,28,42,48,53,95],"class_list":["post-305","post","type-post","status-publish","format-standard","hentry","category-technical","tag-android","tag-computer","tag-fix","tag-htc","tag-imap","tag-workaround"],"_links":{"self":[{"href":"http:\/\/www.michaelm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.michaelm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.michaelm.info\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.michaelm.info\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.michaelm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=305"}],"version-history":[{"count":0,"href":"http:\/\/www.michaelm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/305\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.michaelm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.michaelm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=305"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.michaelm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}