Athena
Part III ยท Use
Chapter 8

Mail and calendar: reading an account without holding its keys

How a program on your own machine reads your mail and calendar with a right to read and nothing more: a sign-in it never sees, a renewal key that opens on one machine only, the messages that are never written, whose words are whose when strangers write to you by name, and how to store an event that keeps changing.

After this chapter you should be able to
  • Let a program on a person's own machine read their mail and calendar without it ever seeing a password or being able to send anything.
  • Keep the one lasting secret of a sign-in so that the file is useless anywhere else.
  • Decide, by code, which messages are never written down and what is cut from the rest.
  • Tell the owner's own words from other people's by the account a message came from, not by what it says.
  • Store something that changes after it is made, such as a calendar event, in files that are only ever added to.

8.1Why the screen is not enough

Watching the screen (Chapter 2) records what a person looked at. It misses most of what was sent to them, and it sees a calendar only when the calendar happens to be open. Mail and calendar say who and when in a way a window title cannot: who the owner writes to, what they agreed to attend, what is coming on Thursday. They are also the two places where the most text written by strangers arrives, addressed to the owner by name. So this source brings the largest gain and the largest risk together, and the rules of Chapter 4 have to hold here before anything else.

8.2Asking only to read

There are three ways a local program can get at a mailbox, and they differ in what the program ends up holding.

Definition
App password
A second password for the whole mailbox, made in the account's settings. Quick to set up. Whoever holds it can read, send and delete, and it skips the second step of sign-in.
A connector service
A company that holds the sign-in for you and answers requests on your behalf. Nothing to set up, but every message passes through a third party, and each request is billed.
OAuth with a read scope
The owner signs in on the mail service's own page and approves a named, limited right. The program receives a key that can do only that, and the service enforces the limit.

Athena uses the third. It asks for two rights, to read mail and to read the calendar, and the code refuses to keep a sign-in that came back with anything wider. The limit is therefore not a promise made by Athena: the mail service will not accept a send or a delete from this key whatever the program does.

The sign-in itself follows what the services ask of a program on a desktop. The browser is sent to the service. The answer comes back to an address on the same machine that exists for a few minutes and then closes. A one-time proof, made before the browser was opened and checked by the service at the end, ties the answer to the request, so another program that catches the answer cannot use it. An answer that does not carry this sign-in's own mark is refused before anything is spent.

What is left afterwards is a renewal key. It is encrypted with Windows' own per-user protection before it is written, so the file opens only for the same Windows user on the same machine. Copy the data folder elsewhere and the mail is not reachable from it.

A cost of doing it this way

A service has to know which program is asking. A company shipping to thousands registers once and passes a security review. A program you run for yourself has no such registration, so the owner makes one, in the service's developer console, before the first sign-in. That is a quarter of an hour of clicking that the other two routes do not need. It is the price of holding no more than a right to read.

8.3What is never written

A mailbox holds things a screen recorder would rarely catch: one-time codes, password-reset links, bank statements, payslips. The rules that kept those off the disk in Chapter 3 are applied again here, with three additions that only make sense for mail.

  • Left out whole. Anything labelled spam, bin, draft or promotion. Anything from a sender on the never-record list, which is the list of sites already used for windows, applied to the sender's domain, plus patterns for addresses that send alerts and codes. Anything whose subject says it is a code, a reset, a sign-in notice or a statement. For such a message nothing is kept, not the sender and not the subject; only a count goes up.
  • Cut from what is kept. Earlier messages quoted underneath, and forwarded ones, so that a message holds its author's words only. Text that the HTML hides from a human reader (zero size, invisible, a hidden preheader), because nobody chose to send the owner words they cannot see, and hidden text is where instructions to an assistant are put. The query of every web address, since reset and unsubscribe links are keys. Then the usual removal of keys, codes, card and account numbers.
  • Names only. An attachment is recorded as a file name. Its contents are never fetched.

A pause covers mail as well. While recording is paused, no service is asked anything. And a message that arrived during a pause is not recorded when recording resumes, because each pause is written down as a stretch of time and arrivals are checked against it.

8.4Whose words, decided by the account

For screen text the question of who wrote something was settled by how it was observed. For mail it is settled by the account. A message sent from the owner's own address is theirs. Every other message is somebody else's, however it is worded, and is served inside the same quoting as any text that was merely on screen, with the same check that withholds text reading as an order to an assistant.

Three details follow from taking that seriously.

  • A sender chooses their own display name, so a name is someone else's text and is quoted and checked like a body. An address is served as it is only because it was checked to be shaped like an address.
  • The owner's own sent message is checked too. If what remains after the quoted part was cut still reads as an order, the cutting may have missed something that was not theirs, and it is withheld.
  • A calendar invitation the owner has not accepted says nothing about them. Anyone can send one. It is marked as an invitation, not as an event in the owner's day, until the owner accepts it. The same rule decides who counts as a contact: someone the owner wrote to, or met by an event they made or accepted. A stranger who writes fifty times is not a contact.

8.5Storing something that changes

Everything else in the folder is written once and never altered, which is what lets a record's id say where it is. A calendar event breaks that: it is renamed, moved, deleted. Rewriting old lines would break every id after them.

So an event is filed under the day it starts, and every change is a new line. The newest line for an event wins. When an event moves to another day, a short line saying "moved" is added on the old day, and when it disappears from the calendar a line saying "cancelled" is added, so a reader of one day alone never sees a stale event. Search keeps a list of which line is the newest for each event and drops hits on any other.

8.6Two more rooms

Mail and calendar are scopes of their own (Chapter 6). An agent that was let in before this existed has neither, and gets neither by default. Without the scope, mail does not appear in search, in the answer about a person, or in the list of who the owner wrote to; with it, two more read-only tools answer for recent mail and for the calendar.

8.7What has and has not been checked

All of this is tested against a pretend mail service: the sign-in, the refusals, what is left out, what is cut, the marks, the scopes, signing out and deleting what was read. It has also met one real Google account, once, and that meeting taught three things the pretend service had not.

  • "Slow down" does not always arrive as the code for it. The first read stopped after about two hundred requests on an answer of 403, which usually means "you may not", carrying a reason that meant "too fast". The code now reads the reason, waits and asks again, with longer waits each time.
  • A read that stops part way must keep its place. The list of messages already looked at was saved only at the end of a pass, so a pass that failed would have read the same messages again and stored them twice. Now what was read before the failure is kept and remembered, and the rest waits for the next pass.
  • Do not fetch what you will throw away. Most of those first requests fetched promotions in full only to leave them out. The labels that are never kept are now excluded in the question put to the service, so those messages are never fetched.

On that one mailbox, a few hundred messages were kept, about a fifth of those looked at were left out by sender or subject, and a check by pattern found no kept message still holding a quoted reply or the query of a web address. That is one account on one day, checked by pattern and not by reading. Other services, a busy day, and a week of use are still untried. Chapter 10 carries the state as it changes.

Two things the registration costs that the tests could not show

A registration left in the service's "testing" state gives sign-ins that lapse after seven days. To make them last, the registration has to be published, and the service will not publish one without a public home page and a public privacy policy. So even a program for one person ends up needing a web page that says what it does with the data.