I would like to write a gmail extension that can intercept outgoing emails and modify / squash them if needed. (My exact purpose is data-leak-prevention, but I'd like to keep this question general). Ideally, a domain admin would be able to install it on all email accounts for that domain, but I'll take a solution that works on a per account basis for now, if I can get one.
If I understand correctly, a contextual gadget isn't right, since (among other reasons) it can't intercept email not sent via logging into Gmail via a browser (say, sending email from my account using my iOS client).
The gmail-api (or IMAP/POP) will allow me to access the user's inbox, but not be in-path for outgoing emails.
Is this even possible to do with gmail?
You can route ALL outgoing mail to another mail server using outbound gateway setting or outgoing mail that matches certain criteria using content compliance rules.
OB Gateway: https://support.google.com/a/answer/178333?hl=en
Content Compliance: https://support.google.com/a/answer/1346934?hl=en