Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Asus ExpertCenter PN54 reviewed

    Huawei MatePad Mini: Launch date confirmed for compact flagship tablet with OLED screen

    P40WD-40: New Lenovo ThinkVision monitor leaks with Thunderbolt 4 and 120 Hz refresh rate for professionals

    Facebook X (Twitter) Instagram
    • Artificial Intelligence
    • Business Technology
    • Cryptocurrency
    • Gadgets
    • Gaming
    • Health
    • Software and Apps
    • Technology
    Facebook X (Twitter) Instagram Pinterest Vimeo
    Tech AI Verse
    • Home
    • Artificial Intelligence

      Blue-collar jobs are gaining popularity as AI threatens office work

      August 17, 2025

      Man who asked ChatGPT about cutting out salt from his diet was hospitalized with hallucinations

      August 15, 2025

      What happens when chatbots shape your reality? Concerns are growing online

      August 14, 2025

      Scientists want to prevent AI from going rogue by teaching it to be bad first

      August 8, 2025

      AI models may be accidentally (and secretly) learning each other’s bad behaviors

      July 30, 2025
    • Business

      Why Certified VMware Pros Are Driving the Future of IT

      August 24, 2025

      Murky Panda hackers exploit cloud trust to hack downstream customers

      August 23, 2025

      The rise of sovereign clouds: no data portability, no party

      August 20, 2025

      Israel is reportedly storing millions of Palestinian phone calls on Microsoft servers

      August 6, 2025

      AI site Perplexity uses “stealth tactics” to flout no-crawl edicts, Cloudflare says

      August 5, 2025
    • Crypto

      Chainlink (LINK) Price Uptrend Likely To Reverse as Charts Hint at Exhaustion

      August 31, 2025

      What to Expect From Solana in September

      August 31, 2025

      Bitcoin Risks Deeper Drop Toward $100,000 Amid Whale Rotation Into Ethereum

      August 31, 2025

      3 Altcoins Smart Money Are Buying During Market Pullback

      August 31, 2025

      Solana ETFs Move Closer to Approval as SEC Reviews Amended Filings

      August 31, 2025
    • Technology

      Asus ExpertCenter PN54 reviewed

      August 31, 2025

      Huawei MatePad Mini: Launch date confirmed for compact flagship tablet with OLED screen

      August 31, 2025

      P40WD-40: New Lenovo ThinkVision monitor leaks with Thunderbolt 4 and 120 Hz refresh rate for professionals

      August 31, 2025

      Best AI Workstation Processors 2025: Why AMD Ryzen Beats Intel for Local AI Computing for now!

      August 31, 2025

      How to turn a USB flash drive into a portable games console

      August 31, 2025
    • Others
      • Gadgets
      • Gaming
      • Health
      • Software and Apps
    Check BMI
    Tech AI Verse
    You are at:Home»Technology»Gmail to SQLite
    Technology

    Gmail to SQLite

    TechAiVerseBy TechAiVerseMay 10, 2025No Comments4 Mins Read4 Views
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Gmail to SQLite
    Share
    Facebook Twitter LinkedIn Pinterest WhatsApp Email

    BMI Calculator – Check your Body Mass Index for free!

    Gmail to SQLite

    Gmail to SQLite

    This is a script to download emails from Gmail and store them in a SQLite database for further analysis. I find it extremely useful to have all my emails in a database to run queries on them. For example, I can find out how many emails I received per sender, which emails take the most space, and which emails from which sender I never read.

    Installation

    1. Clone this repository: git clone https://github.com/marcboeker/gmail-to-sqlite.git.
    2. Install the requirements: pip install -r requirements.txt
    3. Create a Google Cloud project here.
    4. Open Gmail in API & Services and activate the Gmail API.
    5. Open the OAuth consent screen and create a new consent screen. You only need to provide a name and contact data.
    6. Next open Create OAuth client ID and create credentials for a Desktop app. Download the credentials file and save it under credentials.json in the root of this repository.

    Here is a detailed guide on how to create the credentials: https://developers.google.com/gmail/api/quickstart/python#set_up_your_environment.

    Usage

    Sync all emails

    1. Run the script: python main.py sync --data-dir path/to/your/data where -- is the path where all data is stored. This creates a SQLite database in /messages.db and stores the user credentials under /credentials.json.
    2. After the script has finished, you can query the database using, for example, the sqlite3 command line tool: sqlite3 /messages.db.
    3. You can run the script again to sync all new messages. Provide --full-sync to force a full sync. However, this will only update the read status, the labels, and the last indexed timestamp for existing messages.

    Sync a single message

    python main.py sync-message --data-dir path/to/your/data --message-id

    Commandline parameters

    usage: main.py [-h] [--data-dir DATA_DIR] [--update] {sync, sync-message}
    
    Main commands:
    sync                    Sync emails from Gmail to the database.
    sync-message            Sync a single message from Gmail to the database.
    
    --data-dir DATA_DIR     Path to the directory where all data is stored.
    --full-sync             Force a full sync.
    --message-id MESSAGE_ID Sync only the message with the given message id.
    

    Schema

    CREATE TABLE IF NOT EXISTS "messages" (
        "id" INTEGER NOT NULL PRIMARY KEY, -- internal id
        "message_id" TEXT NOT NULL, -- Gmail message id
        "thread_id" TEXT NOT NULL, -- Gmail thread id
        "sender" JSON NOT NULL, -- Sender as JSON in the form {"name": "Foo Bar", "email": "foo@example.com"}
        "recipients" JSON NOT NULL, -- JSON object: {
          -- "to": [{"email": "foo@example.com", "name": "Foo Bar"}, ...],
          -- "cc": [{"email": "foo@example.com", "name": "Foo Bar"}, ...],
          -- "bcc": [{"email": "foo@example.com", "name": "Foo Bar"}, ...]
        --}
        "labels" JSON NOT NULL, -- JSON array: ["INBOX", "UNREAD", ...]
        "subject" TEXT NOT NULL, -- Subject of the email
        "body" TEXT NOT NULL, -- Extracted body either als HTML or plain text
        "size" INTEGER NOT NULL, -- Size reported by Gmail
        "timestamp" DATETIME NOT NULL, -- When the email was sent/received
        "is_read" INTEGER NOT NULL, -- 0=Unread, 1=Read
        "is_outgoing" INTEGER NOT NULL, -- 0=Incoming, 1=Outgoing
        "last_indexed" DATETIME NOT NULL -- Timestamp when the email was last seen on the server
    );

    Example queries

    Get the number of emails per sender

    Show the number of unread emails by sender

    This is great to determine who is spamming you the most with uninteresting emails.

    Get the number of emails for a specific period

    • For years: strftime('%Y', timestamp)
    • For months in a year: strftime('%m', timestamp)
    • For days in a month: strftime('%d', timestamp)
    • For weekdays: strftime('%w', timestamp)
    • For hours in a day: strftime('%H', timestamp)

    SELECT strftime('%Y', timestamp) AS period, COUNT(*) AS count
    FROM messages
    GROUP BY period
    ORDER BY count DESC

    Find all newsletters and group them by sender

    This is an amateurish way to find all newsletters and group them by sender. It’s not perfect, but it’s a start. You could also use

    Show who has sent the largest emails in MB

    Count the number of emails that I have sent to myself

    List the senders who have sent me the largest total volume of emails in megabytes

    Roadmap

    • Detect deleted emails and mark them as deleted in the database.

    BMI Calculator – Check your Body Mass Index for free!

    Share. Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Telegram Email
    Previous ArticleVision Now Available in Llama.cpp
    Next Article How cloud and AI transform and improve customer experiences
    TechAiVerse
    • Website

    Jonathan is a tech enthusiast and the mind behind Tech AI Verse. With a passion for artificial intelligence, consumer tech, and emerging innovations, he deliver clear, insightful content to keep readers informed. From cutting-edge gadgets to AI advancements and cryptocurrency trends, Jonathan breaks down complex topics to make technology accessible to all.

    Related Posts

    Asus ExpertCenter PN54 reviewed

    August 31, 2025

    Huawei MatePad Mini: Launch date confirmed for compact flagship tablet with OLED screen

    August 31, 2025

    P40WD-40: New Lenovo ThinkVision monitor leaks with Thunderbolt 4 and 120 Hz refresh rate for professionals

    August 31, 2025
    Leave A Reply Cancel Reply

    Top Posts

    Ping, You’ve Got Whale: AI detection system alerts ships of whales in their path

    April 22, 2025168 Views

    6.7 Cummins Lifter Failure: What Years Are Affected (And Possible Fixes)

    April 14, 202548 Views

    New Akira ransomware decryptor cracks encryptions keys using GPUs

    March 16, 202530 Views

    Is Libby Compatible With Kobo E-Readers?

    March 31, 202528 Views
    Don't Miss
    Technology August 31, 2025

    Asus ExpertCenter PN54 reviewed

    Asus ExpertCenter PN54 reviewed – what the mini PC with AMD Ryzen AI 7 350…

    Huawei MatePad Mini: Launch date confirmed for compact flagship tablet with OLED screen

    P40WD-40: New Lenovo ThinkVision monitor leaks with Thunderbolt 4 and 120 Hz refresh rate for professionals

    Best AI Workstation Processors 2025: Why AMD Ryzen Beats Intel for Local AI Computing for now!

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo

    Subscribe to Updates

    Get the latest creative news from SmartMag about art & design.

    About Us
    About Us

    Welcome to Tech AI Verse, your go-to destination for everything technology! We bring you the latest news, trends, and insights from the ever-evolving world of tech. Our coverage spans across global technology industry updates, artificial intelligence advancements, machine learning ethics, and automation innovations. Stay connected with us as we explore the limitless possibilities of technology!

    Facebook X (Twitter) Pinterest YouTube WhatsApp
    Our Picks

    Asus ExpertCenter PN54 reviewed

    August 31, 20252 Views

    Huawei MatePad Mini: Launch date confirmed for compact flagship tablet with OLED screen

    August 31, 20252 Views

    P40WD-40: New Lenovo ThinkVision monitor leaks with Thunderbolt 4 and 120 Hz refresh rate for professionals

    August 31, 20252 Views
    Most Popular

    Xiaomi 15 Ultra Officially Launched in China, Malaysia launch to follow after global event

    March 12, 20250 Views

    Apple thinks people won’t use MagSafe on iPhone 16e

    March 12, 20250 Views

    French Apex Legends voice cast refuses contracts over “unacceptable” AI clause

    March 12, 20250 Views
    © 2025 TechAiVerse. Designed by Divya Tech.
    • Home
    • About Us
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.