dmc

dynamic mail client
git clone git://git.suckless.org/dmc
Log | Files | Refs | README | LICENSE

pipeline (3524B)


      1 mail protocols
      2 ==============
      3 imap4, pop3 ... are implemented as a simple unix-like applications which
      4 parses a simple shell-like input and convert them into protocol-specific
      5 queries.
      6 
      7 The network layer is abstracted by pipes, so you can use any application
      8 to provide a transport layer to the protocol. This is 'netcat' for plain
      9 TCP connections and 'openssl s_client' for SSL ones.
     10 
     11 From this point you need a fifo input to feed the program with commands
     12 and a fifo to get the result of the command.
     13 
     14 The mail handler pipeline can be described as follows:
     15 
     16 
     17                            protocol input
     18                       .----------------------------------.
     19                       V                                  |
     20  +-------+        +-------+          +---------+         |
     21  | input | stdin  | pop3  | stdout   | netcat  | stdout  |
     22  | fifo  |------->| imap4 |--------->| openssl |---------'
     23  +-------+        +-------+          +---------+
     24                     |  |
     25                     |  | stderr    +--------+  +--------+
     26                     |  `---------->| status |  | parsed |
     27                     |              +--------+  | output |
     28                     | secondary output         | result |
     29                     `------------------------->| of cmd |
     30                                                +--------+
     31 
     32 The understanding of this pipe graph reveals that the protocol application
     33 requires two input channels and three output ones.
     34 
     35 Three of them are just the basic stdin, stdout, stderr filedescriptors,
     36 and the other two are used to get feedback from the communication channel
     37 and dump the result of the command to a file.
     38 
     39 In a posix shell you can implement the pipeline in this way:
     40 
     41   $ rm -f input fifo-in fifo-out output
     42   $ mkfifo input fifo-in fifo-out
     43   $ :> output
     44   $ (while : ; do cat input ; done ) | \
     45     dmc-pop3 fifo-in output 2> fifo-out | nc host port > fifo-in
     46 
     47 In this way the fifo-in fifo file is used to push commands to the daemon.
     48 
     49 The fifo-out is used for the parent application to get notifications
     50 when the command has been completely executed. Timeouts are suposed to
     51 be handled by the protocol handler and the manager application should
     52 understand that all those protocols are not going to give you results
     53 inmediately.
     54 
     55 An implementation of a manager tool for the previous daemon is:
     56 
     57   $ echo login user pass > fifo-in
     58   $ cat fifo-out # lock until command is executed
     59   $ cat output   # retrieve result of command
     60   ...
     61 
     62 The simplest way to test if a protocol handler is working properly is:
     63 
     64   $ dmc-pop3 fifo-in /dev/stderr | nc host port > fifo-in
     65 
     66 The pipe graph can be hardly simplified if we embed the transport
     67 layer inside the program.
     68 
     69                _________________
     70               / ssl, host, port \
     71               \______,  ________/
     72                       \|
     73  +-------+        +-------+ stdout      +--------+
     74  | input | stdin  | pop3  |------------>| status | fifo lock
     75  | fifo  |------->| imap4 |--------.    +--------+
     76  +-------+        +-------+ stderr  \   +--------+
     77                                      `->| output | truncated file
     78                                         +--------+
     79 
     80 In this way the *nix pipeline becomes:
     81 
     82   $ dmc-pop3 tcp host port
     83 
     84 And the daemon pipeline will look like:
     85 
     86   $ mkfifo input outlock
     87   $ :> output
     88   $ (while : ; do cat input ; done ) | dmc-pop3 host port 2> outlock > output
     89 
     90 PROs:
     91  - the pipeline is simpler
     92  - the transport can change from plain to ssl
     93 
     94 CONs:
     95  - ssl cert checks needs to be done inside the application