Module Pop3

This module defines a wrapper around the POP3 proxy implemented in Zorp.

Imported modules

Class Pop3Proxy

This proxy implements the pop3 protocol as specified in rfc1939

Usage

Default processing of commands

By default accept all recommended commands wroten in rfc1939. And the following optional commands: USER, PASS, AUTH. It's knowing about all commands in rfc1939 and the AUTH command. If you want to enable this commands too, you may enable this by hand, or use Pop3ProxyFull

Setting policy for commands

Changing the default behaviour of commands can be done using the hash named "command". This hash is indexed by the command name (e.g: USER or AUTH), and each item in this hash is an action tuple, defining proxy behaviour for the given command.

The first item in this tuple is an integer value, determining the action to take, and also the interpretation of the remaining items in the tuple.

Possible values for the first item

Example 4-8. Sample for converting simple USER/PASS authentication to APOP in POP3

                class UToAPop3(Pop3Proxy):
                  def config(self)
                    Pop3Proxy.config(self)
                    self.commands["USER"] = (Pop3.POP3_CMD_POLICY,self.DropUSER)
                    self.comamnds["PASS"] = (Pop3.POP3_CMD_POLICY,self.UToA)

                  def DropUSER(self,command)
                    self.response = "+OK"
                    self.response_param = "User ok Send Password"
                    return Z_DENY

                  def UToA(self,command)
                    # We got username in self->username,
                    # password in self->command_param,
                    # and the server timestamp in self->timestamp
                    # therefore we can calculate the digest
                    # NOTE: This is a sample only, calcdigest must be
                    # implemented separately
                    digest = calcdigest(self->timestamp+self->command_param)
                    self->command = "APOP"
                    self->command_param = name + " " + digest
                    return Z_ACCEPT

Attributes

Table 4-79. Attributes for class Pop3Proxy

timeout(int) timeout in milisec. If no packet in this intervall, connections will be dropped. (C:RW;P:R, Default: 60 sec)
username(string) Used username in connection. (C:-;P:R, Default: - )
commands(hash) normative policy hash, directing the proxy to do something with requests, without the need to call Python. indexed by the command (e.g. "USER", "UIDL" etc) (C:-;P:RW, default: empty)
command(string) When a command goes up to policy level, you may change it with this.
command_param(string) When a command goes up to policy level, you may change it with this.
response(string) When a command or response goes up to policy level, you may change it with this.
response_param(string) When a command or response goes up to policy level, you may change it with this.
timestamp(string) If pop3 server implements APOP command, it's send a timestamp with greeting, and it's used with APOP Pop3 Proxy save timestamp in this string
answer_multiline(boolean) It's must set in policy, when a command answer is multiline.
permit_empty_command (boolean) Enable lines without commands. (Default: FALSE)

Constructor __init__

Initialize a Pop3Proxy instance.

Synopsis

__init__ ( self,  session )

Description

Create and set up a Pop3Proxy instance.

Arguments

Table 4-80. Arguments for Pop3Proxy.__init__()

selfthis instance
sessionsession this instance belongs to

Method config

Default Pop3 config

Synopsis

config ( self )

Description

Fill commands hash with most common values. (It's work for all pop3 client know by me)