File common.lua
Commonly used POP3 implementation. These functions need a stat(pstate) that checks if it called more than once.
The callback factory for retr and top:
A callback factory is a function that generates other functions. both retr and top need a callback. the callback is called when there is some data to send to the client. this is done with popserver_callback(s,data) where s is the data and data is the opaque data that is passed to the retr/top function and is used internally by the popserve callbak. no need to know what it is, but we have to pass it.
The callback function must accept 2 args: the data to send and an optional error message. if the data is nil it means the err contains the relative error message. If s is "" it means that the trasmission ended sucesfully (read: the socket has benn closed correclty).
Here in the implementation a is an opaque data structure used by the stringhack module. the stringhack module implements some useful string manipulation tasks. tophack keeps track of how many lines have been processed. If more than lines (we talk of lines of mail body) have been processed the returned string will be trucated to the correct line number. dothack simply does a 'sed s/^\.$/../' but is really hard if the data is not divided in lines as in our case (ip packets are not line oriented), so it is implemented in C for you. check_stop checks if the lines amount of lines have already been processed.
Functions
| check_range (pstate, msg) | Checks if a message number is in range |
| dele (pstate, msg) | Mark msg for deletion |
| list (pstate, msg) | Fill msg size |
| list_all (pstate, msg) | Fill all messages size |
| new_global_for_top (lines, size) | This is to create the global argument for top_cb. |
| noop (pstate) | Do nothing |
| retr_cb (data) | A common implementation of the retr_cb used in the retr() function |
| rset (pstate) | Unflag each message merked for deletion |
| top (b, uri, key, tot_bytes, lines, data, truncate) | the TOP function used in raw-message webmails |
| top_cb (global, data, truncate) | The callback for top is really similar to the retr, but checks for purging unwanted data and sets globals.lines to -1 if no more lines are needed |
| uidl (pstate, msg) | Fill msg uidl field |
| uidl_all (pstate) | Fill all messages uidl field |
Functions
- check_range (pstate, msg)
-
Checks if a message number is in range
Parameters
- pstate:
- msg:
- dele (pstate, msg)
-
Mark msg for deletion
Parameters
- pstate:
- msg:
- list (pstate, msg)
-
Fill msg size
Parameters
- pstate:
- msg:
- list_all (pstate, msg)
-
Fill all messages size
Parameters
- pstate:
- msg:
- new_global_for_top (lines, size)
-
This is to create the global argument for top_cb. Remember that if size is nil the truncate parameter to top_cb must be true.
Parameters
- lines: number the number of line we want.
- size: number the size in byte of the mail, can be nil.
Return value:
table the global argument from common.top_cb. - noop (pstate)
-
Do nothing
Parameters
- pstate:
- retr_cb (data)
-
A common implementation of the retr_cb used in the retr() function
Parameters
- data: userdata the data passed to the retr function.
Return value:
function the callback to use with b:pipe_uri(). - rset (pstate)
-
Unflag each message merked for deletion
Parameters
- pstate:
- top (b, uri, key, tot_bytes, lines, data, truncate)
-
the TOP function used in raw-message webmails
Parameters
- b: table the browser.
- uri: string the uri to fetch.
- key: string the key used with session module.
- tot_bytes: number the size of the mailmessage.
- lines:
- data: userdata the data passed to top(pstate,msg,lines,data).
- truncate: bool if the TOP should be implemented with a Range header field or should be implemented dropping the connection.
Return value:
number POPSERVER_ERR_*. - top_cb (global, data, truncate)
-
The callback for top is really similar to the retr, but checks for purging unwanted data and sets globals.lines to -1 if no more lines are needed
Parameters
- global: table you should read common.lua to understand all the fields.
- data: userdata the data passed to top().
- truncate: bool if we should truncate the commection when done or not.
Return value:
function the callback for b:pipe_uri(). - uidl (pstate, msg)
-
Fill msg uidl field
Parameters
- pstate:
- msg:
- uidl_all (pstate)
-
Fill all messages uidl field
Parameters
- pstate: