[
    {
        "role": "user",
        "content": "I%27m%20using%20mbsync%20to%20sync%20my%20gmail%20to%20my%20local%20host%20in%20folder%20%7E%2Fmaildir%2Fmail.%20Some%20of%20the%20Gmail%20folders%20are%20coming%20in%20under%20%5BGmail%5D%20directory%20and%20I%27d%20like%20to%20move%20them%20to%20the%20root%20directory%20using%20a%20mapping.%20Give%20mbsyncrc%20config"
    },
    {
        "role": "assistant",
        "content": "Here\u2019s an `~/.mbsyncrc` sample that syncs your Gmail account using `mbsync` (a.k.a. `isync`), but remaps the usual `[Gmail]/Sent Mail`, `[Gmail]/Starred`, etc., directories so they show up in **your local Maildir root** (i.e. under `~/maildir/`) instead of under `~/maildir/[Gmail]/\u2026`.\n\nSpecifically:\n\n- We use `Flatten .` so that `/` hierarchy under Gmail collapses (so `[Gmail]/Sent Mail` \u2192 `Sent Mail`).\n- We use patterns to include or exclude specific Gmail subfolders.\n- We map `INBOX` as usual.\n- Remote is Gmail via IMAPS (port 993).\n- Local is Maildir with root `~/maildir/mail`, with Inbox at `~/maildir/mail/INBOX`.\n\nFeel free to adjust paths / usernames.\n\n```ini\n# ~/.mbsyncrc\n\n# Global settings\n# Path to SSL certs, verbosity, etc could go here if needed\n\n### Gmail account connection\nIMAPAccount gmail\nHost imap.gmail.com\nPort 993\nUser yourusername@gmail.com\n# Either use Pass or, better, PassCmd to fetch encrypted password\nPassCmd \"gpg -q --for-your-eyes-only --no-tty -d ~/.secret/gmail.gpg\"\nSSLType IMAPS\n# Optionally specify certificate file if needed\nCertificateFile /etc/ssl/certs/ca-certificates.crt\n\nIMAPStore gmail-remote\nAccount gmail\n\nMaildirStore gmail-local\n# Preserve local name with spaces etc.\n# Flatten makes hierarchy be collapsed\nFlatten .\nSubFolders Verbatim\nPath ~/maildir/mail/\nInbox ~/maildir/mail/INBOX\n\n### Channel: mapping between remote and local\nChannel gmail\nFar :gmail-remote:\nNear :gmail-local:\n\n# Which remote mailboxes to sync:\nPatterns INBOX \"*[Gmail]/Drafts\" \"*[Gmail]/Sent Mail\" \"*[Gmail]/All Mail\" \"*[Gmail]/Starred\" \"*[Gmail]/Trash\"\n# Exclude the [Gmail] namespace itself if it's unused\n# Alternatively, include * and then exclude \"[Gmail]*\" but include the specific ones\n\nCreate Both\nSyncState *\n# Other useful options:\nExpunge Both\n# If you want only one-way (remote \u2192 local), could use \"Sync Pull\"\n\n```\n\n---\n\n## What this does, step by step\n\n- **IMAPAccount / IMAPStore** define the remote Gmail endpoint.  \n  We use IMAPS (secure).\n- **MaildirStore gmail-local** sets up the local store:\n  - `Path` defines the root directory for all local mailboxes (`~/maildir/mail/`).\n  - `Inbox` tells where to put messages in the `INBOX` remote.  \n  - `Flatten .` means that remote names with hierarchy delimiter `/` will be translated to flat names separated by `.` (so `[Gmail]/Sent Mail` becomes `Sent Mail`).  \n  - `Subfolders Verbatim` instructs that the folder hierarchy (where relevant) is preserved if not flattened; here it's mostly relevant for defining how subfolders under `[Gmail]` are recognized.  \n- **Channel gmail** wires remote and local stores together:\n  - `Patterns` picks which remote mailboxes we care about syncing. Only the ones listed under Gmail are pulled in (plus the INBOX).\n  - `Create Both` will auto-create missing mailboxes locally (and remotely if settings allow).  \n  - `SyncState *` keeps the state files inside each local mailbox folder, simplifying backup / deletion.  \n  - `Expunge Both` removes messages marked deleted on either side.\n\n---\n\n## Example final `.mbsyncrc` with custom names\n\nIf you want to *rename* Gmail\u2019s folder names further, for instance calling `[Gmail]/Sent Mail` \u2192 `Sent`, `[Gmail]/Drafts` \u2192 `Drafts`, etc., you can do that by creating separate **Channels** for each, naming the local box explicitly. This is more verbose but gives you explicit control.\n\nHere\u2019s how:\n\n```ini\n# ~/.mbsyncrc\n\nIMAPAccount gmail\nHost imap.gmail.com\nPort 993\nUser yourusername@gmail.com\nPassCmd \"gpg -q --for-your-eyes-only --no-tty -d ~/.secret/gmail.gpg\"\nSSLType IMAPS\nCertificateFile /etc/ssl/certs/ca-certificates.crt\n\nIMAPStore gmail-remote\nAccount gmail\n\nMaildirStore gmail-local\nFlatten .\nSubFolders Verbatim\nPath ~/maildir/mail/\nInbox ~/maildir/mail/INBOX\n\n# Channel for Inbox (already root)\nChannel gmail-inbox\nFar :gmail-remote:INBOX\nNear :gmail-local:INBOX\nCreate Both\nSyncState *\nExpunge Both\n\n# Sent Mail\nChannel gmail-sent\nFar :gmail-remote:[Gmail]/Sent Mail\nNear :gmail-local:Sent\nCreate Both\nSyncState *\nExpunge Both\n\n# Drafts\nChannel gmail-drafts\nFar :gmail-remote:[Gmail]/Drafts\nNear :gmail-local:Drafts\nCreate Both\nSyncState *\nExpunge Both\n\n# All Mail (optional heavy folder)\nChannel gmail-all\nFar :gmail-remote:[Gmail]/All Mail\nNear :gmail-local:AllMail\nCreate Both\nSyncState *\nExpunge Both\n\n# Starred / Important\nChannel gmail-starred\nFar :gmail-remote:[Gmail]/Starred\nNear :gmail-local:Starred\nCreate Both\nSyncState *\nExpunge Both\n```\n\n---\n\nIf you want, I can adapt this for your specific case (mail paths, which Gmail folders you use) so you can just drop in your configuration. Would you prefer I tailor it for your folder list?"
    }
]