Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
ceb9dd9c
Commit
ceb9dd9c
authored
Apr 30, 1998
by
Jeffrey Shell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first step in some new cleanups.
parent
4b9c9a7d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
45 deletions
+70
-45
lib/python/Products/MailHost/MailHost.py
lib/python/Products/MailHost/MailHost.py
+70
-45
No files found.
lib/python/Products/MailHost/MailHost.py
View file @
ceb9dd9c
...
@@ -3,14 +3,15 @@
...
@@ -3,14 +3,15 @@
from
Globals
import
Persistent
,
HTMLFile
,
HTML
,
MessageDialog
from
Globals
import
Persistent
,
HTMLFile
,
HTML
,
MessageDialog
from
socket
import
*
;
from
select
import
select
from
socket
import
*
;
from
select
import
select
from
AccessControl.Role
import
RoleManager
from
AccessControl.Role
import
RoleManager
import
Acquisition
,
sys
,
regex
,
string
,
types
from
operator
import
truth
import
Acquisition
,
sys
,
ts_regex
,
string
,
types
import
OFS.SimpleItem
import
OFS.SimpleItem
import
Globals
import
Globals
from
Scheduler.OneTimeEvent
import
OneTimeEvent
from
Scheduler.OneTimeEvent
import
OneTimeEvent
from
ImageFile
import
ImageFile
from
ImageFile
import
ImageFile
#$Id: MailHost.py,v 1.2
8 1998/04/22 20:43:03
jeffrey Exp $
#$Id: MailHost.py,v 1.2
9 1998/04/30 19:04:49
jeffrey Exp $
__version__
=
"$Revision: 1.2
8
$"
[
11
:
-
2
]
__version__
=
"$Revision: 1.2
9
$"
[
11
:
-
2
]
smtpError
=
"SMTP Error"
smtpError
=
"SMTP Error"
MailHostError
=
"MailHost Error"
MailHostError
=
"MailHost Error"
...
@@ -37,11 +38,9 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
...
@@ -37,11 +38,9 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
timeout
=
1.0
timeout
=
1.0
manage_options
=
({
'icon'
:
''
,
'label'
:
'Edit'
,
manage_options
=
({
'icon'
:
''
,
'label'
:
'Edit'
,
'action'
:
'manage_main'
,
'target'
:
'manage_main'
,
'action'
:
'manage_main'
,
'target'
:
'manage_main'
},
},
{
'icon'
:
''
,
'label'
:
'Security'
,
{
'icon'
:
''
,
'label'
:
'Security'
,
'action'
:
'manage_access'
,
'target'
:
'manage_main'
,
'action'
:
'manage_access'
,
'target'
:
'manage_main'
},
},
)
)
__ac_permissions__
=
(
__ac_permissions__
=
(
...
@@ -86,7 +85,7 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
...
@@ -86,7 +85,7 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
headers
,
message
=
newDecapitate
(
messageText
)
headers
,
message
=
newDecapitate
(
messageText
)
if
mto
:
headers
[
'to'
]
=
mto
if
mto
:
headers
[
'to'
]
=
mto
if
mfrom
:
headers
[
'from'
]
=
mfrom
if
mfrom
:
headers
[
'from'
]
=
mfrom
for
requiredHeader
in
(
'to'
,
'from'
,
'subject'
):
for
requiredHeader
in
(
'to'
,
'from'
):
if
not
headers
.
has_key
(
requiredHeader
):
if
not
headers
.
has_key
(
requiredHeader
):
raise
MailHostError
,
"Message missing SMTP Header '%s'"
\
raise
MailHostError
,
"Message missing SMTP Header '%s'"
\
%
requiredHeader
%
requiredHeader
...
@@ -96,7 +95,7 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
...
@@ -96,7 +95,7 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
(
trueself
.
smtpHost
,
trueself
.
smtpPort
,
(
trueself
.
smtpHost
,
trueself
.
smtpPort
,
trueself
.
localHost
,
trueself
.
timeout
,
trueself
.
localHost
,
trueself
.
timeout
,
headers
[
'from'
],
headers
[
'to'
],
headers
[
'from'
],
headers
[
'to'
],
headers
[
'subject'
],
messageText
headers
[
'subject'
]
or
'No Subject'
,
messageText
),
),
threadsafe
=
1
threadsafe
=
1
))
))
...
@@ -110,38 +109,51 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
...
@@ -110,38 +109,51 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
return
"SEND OK"
return
"SEND OK"
def
send
(
self
,
messageText
,
mto
=
None
,
mfrom
=
None
,
subject
=
None
):
def
send
(
self
,
messageText
,
mto
=
None
,
mfrom
=
None
,
subject
=
None
):
if
subject
:
messageText
=
"subject: %s
\
n
%s"
%
(
subject
,
messageText
)
headers
,
message
=
newDecapitate
(
messageText
)
headers
,
message
=
newDecapitate
(
messageText
)
if
not
headers
[
'subject'
]:
messageText
=
"subject: %s
\
n
%s"
%
(
subject
or
'[No Subject]'
,
messageText
)
if
mto
:
if
mto
:
if
type
(
mto
)
is
type
(
's'
):
if
type
(
mto
)
is
type
(
's'
):
mto
=
map
(
string
.
strip
,
string
.
split
(
mto
,
','
))
mto
=
map
(
string
.
strip
,
string
.
split
(
mto
,
','
))
headers
[
'to'
]
=
mto
headers
[
'to'
]
=
filter
(
truth
,
mto
)
if
mfrom
:
headers
[
'from'
]
=
mfrom
if
mfrom
:
for
requiredHeader
in
(
'to'
,
'from'
,
'subject'
):
headers
[
'from'
]
=
mfrom
for
requiredHeader
in
(
'to'
,
'from'
):
if
not
headers
.
has_key
(
requiredHeader
):
if
not
headers
.
has_key
(
requiredHeader
):
raise
MailHostError
,
"Message missing SMTP Header '%s'"
\
raise
MailHostError
,
"Message missing SMTP Header '%s'"
\
%
requiredHeader
%
requiredHeader
SendMail
(
self
.
smtpHost
,
self
.
smtpPort
,
self
.
localHost
,
sm
=
SendMail
(
self
.
smtpHost
,
self
.
smtpPort
,
self
.
localHost
,
self
.
timeout
)
self
.
timeout
).
send
(
sm
.
send
(
mfrom
=
headers
[
'from'
],
mto
=
headers
[
'to'
],
mfrom
=
headers
[
'from'
],
mto
=
headers
[
'to'
]
,
subj
=
headers
[
'subject'
]
or
'No Subject'
,
subj
=
headers
[
'subject'
],
body
=
messageText
)
body
=
messageText
)
def
scheduledSend
(
self
,
messageText
,
mto
=
None
,
mfrom
=
None
,
subject
=
None
):
def
scheduledSend
(
self
,
messageText
,
mto
=
None
,
mfrom
=
None
,
subject
=
None
):
if
subject
:
messageText
=
"subject: %s
\
n
%s"
%
(
subject
,
messageText
)
headers
,
message
=
newDecapitate
(
messageText
)
headers
,
message
=
newDecapitate
(
messageText
)
if
mto
:
headers
[
'to'
]
=
mto
if
mfrom
:
headers
[
'from'
]
=
mfrom
if
not
headers
[
'subject'
]:
for
requiredHeader
in
(
'to'
,
'from'
,
'subject'
):
messageText
=
"subject: %s
\
n
%s"
%
(
subject
or
'[No Subject]'
,
if
not
headers
.
has_key
(
requiredHeader
):
messageText
)
raise
MailHostError
,
"Message missing SMTP Header '%s'"
\
if
mto
:
%
requiredHeader
if
type
(
mto
)
is
type
(
's'
):
mto
=
map
(
string
.
strip
,
string
.
split
(
mto
,
','
))
headers
[
'to'
]
=
filter
(
truth
,
mto
)
if
mfrom
:
headers
[
'from'
]
=
mfrom
for
requiredHeader
in
(
'to'
,
'from'
):
if
not
headers
.
has_key
(
requiredHeader
):
raise
MailHostError
,
"Message missing SMTP Header '%s'"
\
%
requiredHeader
Globals
.
Scheduler
.
schedule
(
OneTimeEvent
(
Globals
.
Scheduler
.
schedule
(
OneTimeEvent
(
Send
,
Send
,
(
self
.
smtpHost
,
self
.
smtpPort
,
self
.
localHost
,
self
.
timeout
,
(
self
.
smtpHost
,
self
.
smtpPort
,
self
.
localHost
,
self
.
timeout
,
headers
[
'from'
],
headers
[
'to'
],
headers
[
'from'
],
headers
[
'to'
],
headers
[
'subject'
],
messageText
headers
[
'subject'
]
or
'No Subject'
,
messageText
),
),
threadsafe
=
1
threadsafe
=
1
))
))
...
@@ -197,7 +209,7 @@ class SendMail:
...
@@ -197,7 +209,7 @@ class SendMail:
%
(
code
,
line
)
%
(
code
,
line
)
return
1
return
1
def
send
(
self
,
mfrom
,
mto
,
subj
,
body
):
def
send
(
self
,
mfrom
,
mto
,
subj
=
'No Subject'
,
body
=
'Blank Message'
):
self
.
conn
.
send
(
"mail from:<%s>
\
n
"
%
mfrom
)
self
.
conn
.
send
(
"mail from:<%s>
\
n
"
%
mfrom
)
self
.
_check
()
self
.
_check
()
if
type
(
mto
)
in
[
types
.
ListType
,
types
.
TupleType
]:
if
type
(
mto
)
in
[
types
.
ListType
,
types
.
TupleType
]:
...
@@ -217,33 +229,43 @@ class SendMail:
...
@@ -217,33 +229,43 @@ class SendMail:
self
.
conn
.
send
(
"quit
\
n
"
)
self
.
conn
.
send
(
"quit
\
n
"
)
self
.
conn
.
close
()
self
.
conn
.
close
()
def
newDecapitate
(
message
):
def
newDecapitate
(
message
,
req_headers
=
[
'to'
,
'from'
,
'subject'
]):
blank_re
=
regex
.
compile
(
'^[%s]+$'
%
string
.
whitespace
)
blank_re
=
ts_regex
.
compile
(
'^[%s]+$'
%
string
.
whitespace
)
header_re
=
regex
.
symcomp
(
'^
\
(<he
a
derName>[^
\
0
- <>:]+
\
):
\
(<headerText>.*
\
)$
'
)
header_re
=
ts_regex
.
symcomp
(
space_re =regex.compile('
^
[
%
s
]
+
' % string.whitespace)
'^
\
(<he
a
derName>[^
\
0
- <>:]+
\
):
\
(<headerText>.*
\
)$
'
,
ts_regex.casefold)
space_re =ts_regex.compile('
^
[
%
s
]
+
' % string.whitespace)
linecount=0; headerDict={};curHeader={}
# initialize namespace, blank out required headers
maxwell=map(lambda x: string.rstrip(x),string.split(message,'
\
n
'))
linecount=0; hd={};curHeader={}
for rh in req_headers: hd[rh]=''
maxwell=map(string.rstrip, string.split(message,'
\
n
'))
for line in maxwell:
for line in maxwell:
if not line: break
if not line:
if blank_re.match(line) >= 0: break
break
if header_re.match(line) >=0:
if blank_re.match(line) >= 0:
break
if header_re.match(line) >= 0:
curHeader=string.lower(header_re.group('
headerName
'))
curHeader=string.lower(header_re.group('
headerName
'))
h
eaderDict
[curHeader] =
\
h
d
[curHeader] =
\
string.strip(header_re.group('
headerText
'))
string.strip(header_re.group('
headerText
'))
elif space_re.match(line)
>=
0:
elif space_re.match(line)
>=
0:
h
eaderDict[curHeader] = "%s %s" % (headerDict
[curHeader], line)
h
d[curHeader] = "%s %s" % (hd
[curHeader], line)
linecount=linecount+1
linecount=linecount+1
if headerDict.has_key('
to
'):
hd['
to
']=map(string.strip, string.split(hd['
to
'], '
,
'))
headerDict['
to
']=map(
lambda x: string.strip(x),
if hd.has_key('
cc
'):
string.split(headerDict['
to
'], '
,
')
hd['
cc
']=map(string.strip,
)
string.split(hd['
cc
'], '
,
'))
hd['
to
']=hd['
to
'] + hd['
cc
']
# clean out empty strings
hd['
to
']=filter(truth, hd['
to
'])
body=string.join(maxwell[linecount:],'
\
n
')
body=string.join(maxwell[linecount:],'
\
n
')
return h
eaderDict
, body
return h
d
, body
def decapitate(message, **kw):
def decapitate(message, **kw):
#left behind for bw-compatibility
#left behind for bw-compatibility
...
@@ -257,6 +279,9 @@ __init__.need_license=1
...
@@ -257,6 +279,9 @@ __init__.need_license=1
####################################################################
####################################################################
#
#
#$Log: MailHost.py,v $
#$Log: MailHost.py,v $
#Revision 1.29 1998/04/30 19:04:49 jeffrey
#first step in some new cleanups.
#
#Revision 1.28 1998/04/22 20:43:03 jeffrey
#Revision 1.28 1998/04/22 20:43:03 jeffrey
#comma-delimeted strings can now be sent to the .send() method for the
#comma-delimeted strings can now be sent to the .send() method for the
#'
mto
' parameter. MailHost appropriately breaks them into multiple
#'
mto
' parameter. MailHost appropriately breaks them into multiple
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment