python - twisted SMTP server limit incoming email message size -


This is a very basic code that I am using to make SMTP server in twisted:

  by email. Import headers, twisted.internet, import from imported, twisted.mail import from reactor zope.interface import class ConsoleMessage delivery (object) from device: smtp istmp;% s "% (myHostname, clientIP, Smtp.rfc822date ()) "Received:% s from% s with"% s "% header (headerValue) def validateFrom (auto, hello, original): # All addresses are accepted return original def ValidateTo (self, user): # The message sent to the user only "console @ domain" is accepted. User.dest.local == "console": return lambda: increase console message (smtp.SMTPBadRcpt (user) class ConsoleMessage: tool (smtp.imessage) def __init __ (self): self.lines = [] Def line (self, line): self.lines.append (line) def eomReceived (self): print "New message received:" print "\ n" .join (self.lines) self.lines = any Also defer.Sciceed Returns (None) Def ConnectionList (Self): # There was an error, throwing stored lines self.lines = Any class LocalSMTPFactory (smtp.SMTPFactory): def buildProtocol Automatic, SmtpProtocol = smtp.ESMTP () smtpProtocol.delivery = console message delivery () Returns smtpProtocol reactor.list NCP (2025, local SMTfactor ()) reactor.ron ()   

I can get emails, but if I want to cancel incoming message size of 1MB or more, how can I do this?

Note that is ConsoleMessage.lineReceived with each row of the message called . The size of each line (its length is similar, there is no doubt in it). You can get the size of all the lines, as they get and act on the basis of the result.

In addition to this, you can find the SIZE ESMTP extension which allows the server to declare the maximum message size that will be accepted. This Code does not check the handle to replace from the message rows because there is no guarantee that the customer will respect the declared max, but in the case of a smart, collaborative customer, save some useless data transfers.

SIZE is a simple enough extension that you can possibly twist the ESMTP server by twisted.mail.smtp.ESMTP subclass and Extensions can add by adding the method to add it.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -