STUDIO MAIL SYNC 1.0.0
BioInfo Solutions, LLC · portable private mail archive

STATUS
Source package and synthetic tests are prepared. No real mailbox has been
authorized, synchronized, or uploaded. Live service behavior and large-mailbox
performance are not yet verified. This is an operator-run local application,
not a hosted inbox, marketing contact importer, or permanent background service.

START WITH A FICTIONAL DEMO
Requires Python 3.11+ on macOS or Linux (Windows may use WSL2; native Windows is
not supported by the file-lock implementation). No runtime packages are needed.
Extract the source ZIP, enter its studio-mail-sync directory, then run:

  python3 -m studio_mail_sync --archive "$HOME/StudioMailDemo" demo
  python3 -m studio_mail_sync --archive "$HOME/StudioMailDemo" ui

The first command creates three fictional messages with fictional attachments.
The second opens your browser to a viewer bound only to 127.0.0.1. Keep the
terminal open; press Control-C to stop. There is no launch agent, service install,
scheduled task, listening public port, analytics, or external AI call.
If the browser does not open:

  python3 -m studio_mail_sync --archive "$HOME/StudioMailDemo" ui --no-browser

Open the private open-private-viewer.html file reported by the command and click
its link. The file is removed when the viewer exits normally. Restarting the
viewer invalidates the previous session link. Reloaded pages without that link
are locked. Treat the launcher file as private access to your local mail.

SEARCH AND DOWNLOAD
Use the search field and account menu. Search uses a literal SQLite substring
scan (ASCII case-insensitive) over decoded subject, sender, recipients and text parts;
it is not semantic search or a performance-tested large-mailbox index. The
deleted-copy checkbox includes messages confirmed absent at the provider.
Select a message to view decoded text, download retained MIME, or download an
attachment. HTML is shown as text rather than rendered or executed. The exact
Gmail RAW MIME remains the authority when derived text is imperfect.

TURN SELECTED MAIL INTO A STUDIO LESSON INPUT
Check 1–24 messages, enter a title and learning goal, acknowledge your right to
use those selected messages, and choose Export private LESSON intake. The viewer
writes JSON and a provenance sidecar into the archive's private exports folder.
It does not upload the file or call a model. In the Studio LESSON tool, import
the generated mail-lesson-*.json as the authorized source manifest. Keep the
*-provenance.json privately with it; do not use that sidecar as the intake.
Source text contains decoded headers/text parts; exact MIME hashes trace back
to the archive. Attachments are retained but not parsed into learning evidence.
Excerpts are exact quotes, not verified claims, summaries or clinical advice.
The v1 adapter uses UTF-16 locators, up to 10 excerpts/message, 24 messages,
500,000 units/source and 1,000,000 units total. Oversized exports stop instead
of silently dropping source text. Split the selections into explicit batches.

REAL GMAIL AUTHORIZATION — FOR THE FUTURE MACHINE, WHEN CHOSEN
The Archive must remain outside this source repository. Default data location
is ~/Library/Application Support/BioInfo Studio Mail; --archive overrides it.
Business and personal Google mailboxes need separate account-pinned token files.
The current personal connector does not authorize a business-account worker.
Never paste account passwords, client secrets or refresh tokens into a chat.

1. On the chosen machine, create a Google Cloud project with Gmail API enabled
   and a Desktop OAuth client; configure its consent screen/test-user or internal
   Workspace access as appropriate. Workspace administrator policy and Google's
   restricted-scope verification/testing rules can affect authorization. This
   package does not change those policies or provision Google Cloud resources.
2. Save the downloaded Desktop client JSON in an owner-private directory outside
   the source repo. Set directory permissions 0700 and client permissions 0600.
3. Explicitly authorize ONE named account (these are paths/examples, not secrets):

  python3 -m studio_mail_sync auth-gmail \
    --client "$HOME/StudioMailAuth/google-desktop-client.json" \
    --token "$HOME/StudioMailAuth/business-authorization.json" \
    --expected-email your-business@example.com

The system browser uses PKCE plus an expiring local loopback callback. The only
requested scope is gmail.readonly. The actual Gmail profile must match your
expected email before a token is saved. Private token files are permission-
protected plaintext, not an encrypted credential vault; use disk encryption
and keep them off shared/cloud folders. No credentials are stored in this repo.
4. Run the explicitly authorized account into a private local archive:

  python3 -m studio_mail_sync --archive "$HOME/StudioMailArchive" sync-gmail \
    --client "$HOME/StudioMailAuth/google-desktop-client.json" \
    --token "$HOME/StudioMailAuth/business-authorization.json" \
    --expected-email your-business@example.com

Repeat with a separately authorized personal token and expected account to
aggregate multiple mailboxes in the same archive. Account identity is rechecked
before each sync, and identical remote IDs cannot overwrite another account.
No mailbox sending, labeling, read-status modification, deletion or contact sync
is performed by this code. Token exchange/refresh uses Google's OAuth endpoint;
all Gmail resource calls are GET requests.

FULL COVERAGE AND RECOVERY
The initial scan paginates every server-accessible message, including Spam and
Trash, retrieves RAW MIME and retains labels, provider metadata and binary
attachment content. Subsequent runs consume Gmail history. Old history returning
404 triggers a full rescan. Permanent deletion retains local bytes and a tombstone.
An omitted old ID is fetched individually before it is marked missing. A message
deleted before it was downloaded may leave only a tombstone, not recovered bytes.
Already purged mail, inaccessible delegated/other accounts and unavailable server
content cannot be reconstructed. This is an archive, not a provider restore tool.

Pending pages/jobs and cursors are stored transactionally. A failure or pause
retains the checkpoint; rerun the same sync command. --max-messages N deliberately
pauses and reports completed:false. No cursor advances past unfinished jobs.
--full asks for a fresh full scan when no scan is pending. If a retained list-page
token has expired, first inspect status, then use --restart-full explicitly to
abandon that checkpoint and rescan. Retained messages are kept. Network retries
are bounded; the application does not claim success after a failed operation.
--restart-full is not a remote deletion or a local archive wipe.

LOCAL EXPORTS FROM OTHER PROVIDERS
Gmail is the implemented server adapter. Outlook/Graph, Yahoo, AOL and general
IMAP OAuth adapters are not implemented in this release. You can explicitly
import a standard EML or MBOX export from a provider, without account access:

  python3 -m studio_mail_sync --archive "$HOME/StudioMailArchive" import-eml \
    --identity your-account@example.com /path/to/exported-message.eml
  python3 -m studio_mail_sync --archive "$HOME/StudioMailArchive" import-mbox \
    --identity your-account@example.com /path/to/exported-mailbox.mbox

EML retains exactly the supplied file bytes. MBOX retains the parser's MIME
representation after container-envelope removal/line-ending normalization;
it is not a claim about original wire bytes. Imports do not establish complete
server coverage, incremental provider sync, original provider label fidelity,
or deleted-message recovery. Native Mail permissions/cache are not accessed.

VERIFY, MOVE, AND REMOVE
  python3 -m studio_mail_sync --archive "$HOME/StudioMailArchive" status
  python3 -m studio_mail_sync --archive "$HOME/StudioMailArchive" verify
  python3 -m unittest discover -s tests -v

For a full move, stop sync and the viewer first, then copy the ENTIRE private
archive directory (database, WAL/SHM if present, objects, exports and state)
through your chosen private transfer path. Keep the new directory 0700 and
files 0600; run verify on the destination. The source repository alone does not
contain your mail. Auth client/tokens are separate private material; prefer a
fresh authorization on the destination, then repeat sync there. Never publish
the archive, token files, launcher or exports in GitHub, the Vault or Vercel.

To remove, stop the foreground commands. Delete the extracted source directory
and, only if you intend to discard that data, the explicit private archive/demo
and auth directories you chose. There is no persistent service to uninstall.
Revoke the dedicated OAuth client in Google Account permissions if access is
no longer wanted. Deleting a local token does not revoke Google's grant.
Keep or transfer any mail you want before deleting its only local archive.

REPRODUCIBLE SOURCE HANDOFF
  python3 scripts/build_release.py
Creates a deterministic source ZIP, per-file SHA-256 manifest and repo-release.json.
The allowlist includes only authored source, docs, tests and build instructions.
Credentials, real mail, databases, caches, exports and temporary demo files are
excluded. Run tests first. Store listing/fees belong to the current Vault pricing
policy; this portable learner/operator package embeds no price or entitlement.

OFFICIAL REFERENCES
https://developers.google.com/workspace/gmail/api/guides/sync
https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.messages/get
https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.history/list
https://developers.google.com/identity/protocols/oauth2/native-app
