-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Mox for Delta Chat #251
Comments
Hi, interesting topic and there certainly is overlap in goals. It's a goal of mox itself to be easy to install and run. Automating the About the topics:
The chatmail page mentions push notifications. Mox does implement IMAP IDLE, I'll be happy to answer questions and the mox code, and give pointers & help |
Awesome! I'm glad to hear that this sort of thing would be welcome. I'll reply point-by-point (with some minor re-ordering) below:
Oooh, cool! That's a nice bit of overlap :) Milter support
Maddy avoids the complexities of full milter support by… also not having it, lol. (See the first three paragraphs of Maddy's documentation of their milter support.) That said, even just being able to accept/reject emails via a standardized interface is a useful feature.
Yep, that's correct.
This is an interesting possibility. I am initially hesitant to go all-in on building things directly into Mox, because, from Mox's perspective, all of the chatmail stuff is a weird growth stuck to the side of an email server. I wouldn't want to write all of this stuff, upstream it into Mox, and then (heaven forbid) get hit by a bus and leave you with the maintenance burden for code that you may or may not even want to use. If the chatmail mechanisms are separated through standardized interfaces (like milter, Dovecot SASL, etc.), Mox can make good use of those interfaces regardless of what kind of thing is connected to them! (For the record, I have no plans to disappear—I just want to make realistic plans for the long-term maintenance of the things I build! I have learned the hard way that if I don't make those plans up front, I end up building things that suck to maintain, and which I eventually give up on.) The major wrinkle in building a standardized interface for all of the pieces here is that I don't know of any existing mechanism for providing external tools access to all of the emails for every account—except for maildir, which would be an enormous rewrite and would sacrifice many performance benefits gained by having a database. I don't think that maildir would be a good idea. I'll describe how I was planning to implement the interfaces for data cleanup and push notifications below. External Authentication
As far as I know, all of the Delta Chat clients (including the forks and third-party ones) use a core library written by the main developers called deltachat-core-rust.
The deltachat-core library only uses XOAUTH2 or PLAIN/LOGIN SASL mechanisms for authenticating to the server (IMAP code, SMTP code). I don't know for sure, but I think that XOAUTH2 is only used when talking to one of the major email providers (Gmail, Office 365, etc.), because they don't allow anything else. None of the code in the main chatmail server sets up an OAuth identity provider.
Maddy accomplishes this by allowing server administrators to delegate authentication to external modules using the Dovecot SASL protocol. Here's the documentation, but I can't pinpoint exactly where in the code this happens.
All of these could absolutely work! The upstream chatmail server has a Data Retention
This makes sense. When I was figuring out how to do this with Maddy, I planned to read the message metadata out of the database. It's backed by SQLite (or PostgreSQL), so that is a very easy way to look at message dates and clean up old ones. There was also a "last login" field in the user table that I could use to erase old, unused accounts. SQLite and PostgreSQL both support concurrent access by multiple processes though, so the right choice for Mox might be to build it in. Delivery Speed
I poked at this with the /debug/pprof tools last night, but I haven't figured out anything useful yet. I probably need to spend more time reading the code to understand what the profiling data means :P TLS ALPN Multiplexing
This sounds good—plus it should hopefully mean that the rate limiting code needs no changes! Push Notifications
The deltachat-core-rust code uses IMAP IDLE when it's running in the foreground, but it also uses APNS/Play push notifications when in the background on mobile.
It shouldn't be an issue—the Delta Chat folks have solved the complexities around IMAP push notifications by stepping sideways around them. The upstream chatmail server sends a "hey there's a new message for asdfghjkl@chatmail-server.example" notification via HTTP to When planning to do this with Maddy, I intended to use the IMAP Filter mechanism to send the HTTP request every time a new email was delivered. The "filter" wouldn't actually do any filtering. Instead it would write the email address for the account to a pipe, which the rest of the daemon code could read and then start an HTTP request retry loop. This plan was definitely a hack, and building it in would certainly be cleaner.
Fantastic, thank you! I'll try to ask major planning-related questions here, so that other folks can get involved if they'd like (such as the upstream chatmail server developers, who have expressed interest in my side project), and send more nitty-gritty questions about Mox's internals by email to avoid sidetracking the architectural stuff. |
Good to hear your consideration about adding chatmail-specific vs generic functionality, and the potential vanishing vs finishing. I'm not sure yet what the right approach is. If we end up with many config options that are specific for chatmail, than a single mode would probably have been simpler. It looks like some chatmail-specific thing (notifications and cleaning up) have to be in mox anyway. But some functionality would be good to have in general. For milter support, indeed a simplified version may be enough. I think milters are intended to be run during each step in the smtp session. But perhaps we can just do the whole exchange at the end. Would simplify implementation quite a bit, I wasn't looking forward to adding it throughout the smtpserver code. For authentication, if we were to check with another sasl server, we would probably require "plain" as only mechanism. The announced mechanisms would have to be trimmed when such a config option is active. The external server would call back to mox to create the account & email address. For data retention, a periodic goroutine that goes through all accounts and removes old message is probably easiest. Each account has its own message database that we have to go through. For removing stale accounts, we don't have "last login". The store.LoginSession type is only for web-based logins (from memory). I have been wanting to keep track of more details of active and recent sessions, this may be a good trigger to implement that. For push notifications, indeed there is no hook for running custom code when a message is delivered... |
I've been thinking about this over the holidays. If someone wants to configure Mox to be a chatmail server from scratch, they'd need to:
This is rather a lot of steps. I'm starting to see your argument for a "chatmail mode" configuration option. Let's say we do build it that way—would the "chatmail mode" functionality be an argument to |
Yeah, it makes sense as a parameter to the quickstart. And perhaps we can just make add a single "Chatmail" config section to mox.conf or domains.conf that applies to the entire instance (I don't think you want to mix chatmail-functionality with "regular" operation?). Mox.conf has config values that don't change at runtime, while domains.conf is for settings that can change at runtime. I don't think these config settings will be changed at runtime (without a restart?). Then a single section in mox.conf may be good enough. |
@s0ph0s-dog btw, one more thing i noticed about the autoconfig change is that the port 443 endpoint uses password-cleartext while the first and standard port endpoint uses password-encrypted. i suppose that's because of account autoregistration on port 443? or should it also default to password-encrypted on port 443? |
I chose to do that because it matched what was in the upstream autoconfig data, and because that's the only mechanism Delta Chat really uses. I don't think there are any security risks associated with putting that in the autoconfig, because the connection is necessarily over TLS, so it won't expose plaintext passwords to eavesdroppers. Now that I've gone to check, the Delta Chat autoconfig code doesn't even parse the
I think that seems like an attractive choice! One potential wrinkle: does it make sense to have data/account retention settings configured globally, rather than per domain? (Should it be configurable in both places?) That functionality seems like it would have applicability beyond chatmail, and people deploying Mox might find it useful to enable/configure that by itself.
I can imagine a situation where someone might want to have a chatmail server just for friends or co-workers and which doesn't delete accounts automatically, but it seems like more of a stretch to imagine someone with multiple domains in the same Mox instance with different levels of chatmail functionality enabled. Or, to say it differently, I think someone is likely to want to change the amount of chatmail functionality enabled on all of their domains, but less likely to want differing chatmail settings on multiple domains. I think it would be prudent to design things with an eye towards maybe doing that in the future, but it doesn't make sense to build it that way to start with.
Like I mentioned above, I think the data retention stuff might be changed at runtime and in the web admin interface (probably in an effort to deal with running out of disk space), but the rest of it could quite reasonably be done with a server restart. |
Oh also I don't think I've said this yet: my goal currently is to finish figuring out the shape of what needs to be built by discussing it in this issue. Then, we can break it down into sub-issues for each major piece of development work. Now that I've had some exposure to Mox's codebase and you've seen what my patches look like, we can use that experience to decide who should tackle each sub-issue. I'm willing to do basically all of the development work, but I won't mind if you'd prefer to reserve any of the development tasks for yourself! |
Configuring these settings "per domain" may be too tricky. Or at least, we Some suggestions for the config: We could have a top-level Chatmail settings struct in domains.conf, with the
In type "Account" (for domains.conf), we could add:
Enabling chatmail functionality can be dangerous to do for "regular" We could add a simple internal web handler for handling account autosignup. I For implementing account/message cleanup, I would suggest we just start a For removing accounts, we need to know about its last (successful) activity. You can probably test most of the needed changes with mox localserve. My |
intended for deltachat, which doesn't look at the value. encrypted may be a better default. as discussied in #251
Ah yep, that definitely makes more sense. I hadn't discovered that Mox supported a many-to-one address to account mapping yet! Also the postmaster account would need special treatment anyway, so making it an option definitely seems like the right choice.
Yes, these lists seem reasonable. In the top level settings, I'd add:
Yeah, I agree. Should it additionally cause a warning/error when an account has chatmail mode enabled, but the global chatmail flag is not enabled?
I think it would be good enough! I'm plenty happy to stick to the existing web design style—this doesn't need to be a fancy Single-Page Application or anything like that. It needs a title, a QR code (I see Mox already includes a library for this), a
Seems sensible, yeah. I think the notifications should be a similar goroutine started at startup, which gets notified through a channel whenever a message arrives, and takes care of retries.
Yep! I'll build the other parts of the cleanup machinery and leave that part until last, so that you can implement the last login tracking.
Would it be possible to restrict the data collected to just the last login timestamp divided by 86,400 (one day's worth of seconds) when chatmail mode is enabled? That's the smallest amount of information that's still useful to implement the cleanup functionality, and the upstream project does something similar to reduce the amount of information being stored.
Yeah, that's a good idea! "Build one to throw away," and all that.
Ooh, have fun! |
While double-checking some things above, I read through the upstream notifications code again. In the first few passes through it, I did not notice that the notifications server wants just a notification token, not an email address. I traced back to where that token comes from, and the client sets it using the IMAP SETMETADATA command (from RFC 5464), which it seems like Mox does not currently implement. I'm going to talk to the upstream project about whether this can be done a different way. Not only is "implement an entire IMAP extension RFC" a significant expansion in scope, but the current metadata keys include With that in mind, the current task list looks something like this:
|
I think an error may be good, but not entirely sure. It can help prevent accidentally disabling chatmail mode, or making it seem an account/domain has it enabled while it's actually globally disabled.
I had a feeling you would want to keep as little information as possible. Probably best to just store this information in a db file (the new auth.db) in a new type. It can be tracked separately from the more detailed login attempt information, which would be disabled for accounts in chatmail mode. I can add the field. Do you want to make a fork where I can make PRs to?
I can implement it, doesn't seem too complicated, haven't had a need for it yet. But it would be good to know if that key triggers some kind of non-standard functionality provided by dovecot. |
I can foresee frustration where someone tries to turn off chatmail mode and then needs to go turn off the setting on 300 accounts too, but I think "turning a chatmail server into a regular email server" is unlikely enough that it shouldn't be an issue. Error it is!
Oh no, I'm predictable :P
That separation of data sounds reasonable to me! I've added you as a collaborator to my fork. I think it makes sense to use the main branch in my fork as the trunk for chatmail features. (Though that would break the ability to use GitHub's "related issues" feature to automatically close the sub-issues here when PRs are merged to main in my fork.)
It does trigger a non-standard feature: https://doc.dovecot.org/2.3/configuration_manual/dict/#proxy From what I can tell, the upstream project uses this to run arbitrary Python code upon get/set for specific keys. Since we're building support for all this directly into Mox, that level of extensibility is unnecessary. I haven't gotten an answer to my request here yet, but assuming my understanding is correct, I'll need to ensure
If you're willing to implement the metadata extension, go ahead! In the next couple days, I'll write up the sub-issues and then get started on sketch code! |
Hello!
I am working on a hobby project to create an implementation of a chatmail server that is easier to deploy and more user-friendly. My goal is to make it easier for people to use Delta Chat, and hopefully reduce overall reliance on centralized chat platforms like WhatsApp, Telegram, and the like. I was originally going to use Maddy as the email server for this project, but its developer seems to have been inactive on GitHub for a long time. I've stumbled across Mox though, and it seems like a better-maintained choice—one to which I'd be happy to contribute!
In my (limited) testing so far, Mox seems to work well as an email server for Delta Chat:
Chatmail servers also need to do several other things though. Some of them I already have plans to implement on my own, because they don't require any cooperation from the mail server (sign-up web page generation, a P2P data relay, etc.). Here are the things I'd like to discuss adding directly to Mox, because directly building them in might make the most sense:
I'm quite happy to help contribute to the development of all of these features, if the help would be welcome! Is this sort of thing something you'd like to see Mox used for? If so, would you be willing to review my pull requests and offer guidance to me as I work on implementing the parts of these that are inside Mox?
The text was updated successfully, but these errors were encountered: