📜 ⬆️ ⬇️

GMail Offline Database. Export

Hello, Habrasoobschestvo!

I have long wanted to pull out the history of jabber from GMail (in principle, it is quite convenient, but I want to use it without additional barriers)
When a topic came across , I downloaded the message history from GTalk to my computer , I was rejoiced, but, seeing the cumbersome efforts and efforts made to extract it, I decided that the game was not worth the trouble.

Therefore, I decided to go the other way, and understand Google Gears \ GMail Offline.

')

Training


First of all, we need to put gears

Log in to GMail, go to chat rooms and mark with a shortcut (for example, export ) necessary chat sessions.
Next, go to the Gmail Offline Settings , select Enable Gmail Offline for this computer , click the Change shortcut settings link and set Everything opposite the export shortcut (all the rest can be set to No , so as not to download too much.
Then it remains to save the changes and wait until Gears synchronizes the necessary chains with the local host.

Base


Walking through the Firefox directories, I found the Google Gears repository.

The essence is that letters and chats are in the file
% username% @ % servername% -GoogleMail @ % servername% #database
where % servername% is usually gmail.com, but for google services for a domain, it will be your domain respectively.

Note: the file can be called and ... # database [1] and [2] or even without [digit], so if there are no chats in one file, then you will have to try with all (except those in whose name there is -b , -t , -u , this is some kind of service information, it does not interest us)

The database file itself is in % GearsDatabaseDir% / mail.google.com/http_80
where _80 can also be _443 if SSL is used, and % GearsDatabaseDir% for your platform can be found here

As it turned out, the database is in SQLite format. Further - easier. The sqlite3 downloaded from offsite helps us get to the very essence of GMail Offline.

Pull out


First let's check if there are messages for the label we need:
sqlite3 -line "user@gmail.com-GoogleMail@gmail.com#database" "SELECT l.`Label` as `label`,COUNT(*) as messages FROM `Labels` l, Messages m, MessageLabels ml WHERE ml.`LabelId`=l.`LabelId` AND m.`rowid`=ml.`MessageId` AND l.`Label`='export'"

We get:
label = export
messages = 662

So, there are messages, you can start exporting.

Create a header (<html> <body>) and a “footer” (</ body> </ html>) of the future HTML chat file, and run:
sqlite3 -list -separator '\n\n' "user@gmail.com-GoogleMail@gmail.com#database" "SELECT '<h3>'|| datetime(m.`datems`/1000,'unixepoch','+3 hours') || '</h3>' || c.`c1Body` || '<br /><br />' FROM MessagesFT_content c, Messages m, MessageLabels ml, Labels l WHERE ml.`LabelId`=l.`labelId` AND c.`rowid`=ml.`MessageId` AND m.`MessageId`=c.`rowid` AND l.`Label`='export' ORDER BY m.`datems` ASC" > body.html

(+3 hours replaced with your time zone)

And now it remains only to "merge" the files into one.
Under Windows:
copy /B header.tpl + body.html + footer.tpl history_export.html

(if you don’t put / B then under winxp there remains at the end some kind of dumb symbol. for some reason puts it)

Bash:
cat header.tpl >> history_export.html
cat body.html>> history_export.html
cat footer.tpl >> history_export.html


In short, that's all. You can also use html2text, which, given the volume of design (CSS was not used!) - at least rationally.

_________
Thank you for the Dreadatour invite

Source: https://habr.com/ru/post/80288/


All Articles