Welcome, guest | Sign In | My Account | Store | Cart

This script will extract email message bodies from the SQLite database stored in an android phone.

The gmail database is typically located on your phone under the following location:

`\data\data\com.google.android.gm\databases\mailstore.YOURUSERNAME@gmail.com.db`

To use the script, copy the file above from your phone to your machine and rename it to gmail.db.

NOTE: You need a rooted phone in order to get access to the folder above.

Python, 21 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import sqlite3
import zlib

good_chars=',.0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~ '

conn = sqlite3.connect('gmail.db')
cursor = conn.cursor()
cursor.execute("select _id, fromAddress, subject, bodyCompressed from messages")
rows = cursor.fetchall()

for row in rows:
    fname = (str(row[0]) + row[1] + row[2])[:48]
    fname = ''.join([c for c in fname if c in good_chars])
    print fname
    with open(fname + '.html', 'wb') as fout:
        if row[3]:
            data = zlib.decompress(row[3])
            fout.write('<html><body>' + data + '</body></html>')

cursor.close()
conn.close()

1 comment

Miguel Carneiro 8 years, 2 months ago  # | flag

What type of compression is the data stored in ? I've been trying to decompress this in C# with any success .. you have 1 line of code for decompression "data = zlib.decompress(row[3])"

I'm at 15 lines of code now without success.. Keeps telling me that the data is corrupt but the app opens the data fine..