CVS: tmda/TMDA Util.py,1.110.2.1,1.110.2.2
"Jason R. Mastaler" <[email protected]>
| Newsgroups | gmane.mail.spam.tmda.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/tmda/tmda/TMDA
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21029/TMDA
Modified Files:
Tag: release-1-0
Util.py
Log Message:
Bugfix. When AutoResponse.record() tries to write an entry to
~/.tmda/responses/, an IOError (errno.ENAMETOOLONG) is raised if the
filename exceeds the maximum number of chars allowed in a filename
(255 max on POSIX systems).
This came to light when a user received a message with an enormously
long envelope sender address. Surprisingly, rfc 2821 does allow such
lengths (section 4.5.3.1). It only has recommendations on maximum
lengths, and gives the SMTP server the option to refuse, but does not
require it.
To fix, we truncate the sender address in Util.normalize_sender() at
233 chars. Timestamp is a long, max 10 characters; PID might be a
long on 64-bit architectures, so max 10 characters; 2 separator dots
('.') are 2 characters. Therefore, the email address can be a maximum
of 255 - 22 or 233 characters so that the entire filename is <= 255.
Will apply to main trunk as well.
Index: Util.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Util.py,v
retrieving revision 1.110.2.1
retrieving revision 1.110.2.2
diff -u -r1.110.2.1 -r1.110.2.2
--- Util.py 9 Jan 2004 19:21:50 -0000 1.110.2.1
+++ Util.py 25 Jan 2004 18:25:31 -0000 1.110.2.2
@@ -48,6 +48,7 @@
MODE_READ = 04
MODE_WRITE = 02
NL = '\n'
+POSIX_NAME_MAX = 255 # maximum length of a file name
def gethostname():
@@ -449,10 +450,14 @@
outside the directory.
- Spaces are replaced with underscores.
- The address is lowercased.
+ - Truncate sender at 233 chars to insure the full filename
+ (including time, pid, and two dots) fits within the POSIX limit of
+ 255 chars for a filename.
"""
sender = sender.replace(' ', '_')
sender = sender.replace('/', ':')
- return sender.lower()
+ sender = sender.lower()
+ return sender[:POSIX_NAME_MAX - 22]
def confirm_append_address(xp, rp):