maddy

Fork https://github.com/foxcpp/maddy

git clone git://git.lin.moe/go/maddy.git

 1/*
 2Maddy Mail Server - Composable all-in-one email server.
 3Copyright © 2019-2020 Max Mazurov <fox.cpp@disroot.org>, Maddy Mail Server contributors
 4
 5This program is free software: you can redistribute it and/or modify
 6it under the terms of the GNU General Public License as published by
 7the Free Software Foundation, either version 3 of the License, or
 8(at your option) any later version.
 9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program.  If not, see <https://www.gnu.org/licenses/>.
17*/
18
19// Package updatepipe implements utilities for serialization and transport of
20// IMAP update objects between processes and machines.
21//
22// Its main goal is provide maddy command with ability to properly notify the
23// server about changes without relying on it to coordinate access in the
24// first place (so maddy command can work without a running server or with a
25// broken server instance).
26//
27// Additionally, it can be used to transfer IMAP updates between replicated
28// nodes.
29package updatepipe
30
31import (
32	mess "github.com/foxcpp/go-imap-mess"
33)
34
35// The P interface represents the handle for a transport medium used for IMAP
36// updates.
37type P interface {
38	// Listen starts the "pull" goroutine that reads updates from the pipe and
39	// sends them to the channel.
40	//
41	// Usually it is not possible to call Listen multiple times for the same
42	// pipe.
43	//
44	// Updates sent using the same UpdatePipe object using Push are not
45	// duplicates to the channel passed to Listen.
46	Listen(upds chan<- mess.Update) error
47
48	// InitPush prepares the UpdatePipe to be used as updates source (Push
49	// method).
50	//
51	// It is called implicitly on the first Push call, but calling it
52	// explicitly allows to detect initialization errors early.
53	InitPush() error
54
55	// Push writes the update to the pipe.
56	//
57	// The update will not be duplicated if the UpdatePipe is also listening
58	// for updates.
59	Push(upd mess.Update) error
60
61	Close() error
62}