4.9.2.2. Configuring policies for POP3 commands

Changing the default behavior of commands can be done using the hash named request. The hash is indexed by the command name (e.g.: USER or AUTH). See Section 2.1, Policies for requests and responses for details.

ActionDescription
POP3_REQ_ACCEPT

Accept the request without any modification.

POP3_REQ_ACCEPT_MLINE

Accept multiline requests without modification. Use it only if unknown commands has to be enabled (i.e. commands not specified in RFC 1939 or RFC 1734).

POP3_REQ_REJECT

Reject the request. The second parameter contains a string that is sent back to the client.

POP3_REQ_POLICY

Call the function specified to make a decision about the event. See Section 2.1, Policies for requests and responses for details. This action uses two additional tuple items, which must be callable Python functions. The first function receives two parameters: self and command.

The second one is called with an answer, (if the answer is multiline, it is called with every line) and receives two parameters: self and response_param.

POP3_REQ_ABORT

Reject the request and terminate the connection.

Table 4.19.  Action codes for POP3 requests

Example 4.17. Example for allowing only APOP authentication in POP3

This sample proxy class rejects the USER authentication requests, but allows APOP requests.

class APop3(Pop3Proxy):
      def config(self):
              Pop3Proxy.config(self)
              self.request["USER"] = (POP3_REQ_REJECT)
              self.request["APOP"] = (POP3_REQ_ACCEPT)
Example 4.18. Example for converting simple USER/PASS authentication to APOP in POP3

The above example simply rejected USER/PASS authentication, this one converts USER/PASS authentication to APOP authentication messages.

class UToAPop3(Pop3Proxy):
      def config(self):
              Pop3Proxy.config(self)
              self.request["USER"] = (POP3_REQ_POLICY,self.DropUSER)
              self.request["PASS"] = (POP3_REQ_POLICY,self.UToA)

      def DropUSER(self,command):
              self.response_value = "+OK"
              self.response_param = "User ok Send Password"
              return POP3_REQ_REJECT

      def UToA(self,command):
              # Username is stored in self->username,
              # password in self->request_param,
              # and the server timestamp in self->timestamp,
              # consequently the digest can be calculated.
              # NOTE: This is only an example, calcdigest must be
              # implemented separately
              digest = calcdigest(self->timestamp+self->request_param)
              self->request_command = "APOP"
              self->request_param = name + " " + digest
              return POP3_REQ_ACCEPT