The Trunk: Network-tpr.238.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Network-tpr.238.mcz

commits-2
tim Rowledge uploaded a new version of Network to project The Trunk:
http://source.squeak.org/trunk/Network-tpr.238.mcz

==================== Summary ====================

Name: Network-tpr.238
Author: tpr
Time: 2 December 2019, 9:45:46.30357 pm
UUID: abb2a42a-56c3-467b-b070-8e49f1a18016
Ancestors: Network-nice.237

minor refactor and extension of email sending code.
Add support for user name & password when sending emails with a quick utility method - hence SMTPClient class>>#deliverMailFrom:to:text:usingServer:userName:password:
This required a minor refactor to make sure the login was actually done when opening the connection.

=============== Diff against Network-nice.237 ===============

Item was changed:
  ----- Method: ProtocolClient class>>openOnHostNamed: (in category 'instance creation') -----
+ openOnHostNamed: hostNameAndPort
+ "If the hostname uses the colon syntax to express a certain port number we use that instead of the default port number."
- openOnHostNamed: hostName
- "If the hostname uses the colon syntax to express a certain portnumber
- we use that instead of the default port number."
 
+ ^self new openOnHostNamed: hostNameAndPort
- | i |
- i := hostName indexOf: $:.
- i = 0 ifTrue: [
- ^self openOnHostNamed: hostName port: self defaultPortNumber]
- ifFalse: [
- | s p |
- s := hostName truncateTo: i - 1.
- p := (hostName copyFrom: i + 1 to: hostName size) asInteger.
- ^self openOnHostNamed: s port: p]
  !

Item was changed:
  ----- Method: ProtocolClient class>>openOnHostNamed:port: (in category 'instance creation') -----
  openOnHostNamed: hostName port: portNumber
- | serverIP |
- serverIP := NetNameResolver addressForName: hostName timeout: 20.
- serverIP ifNil:[ ^ nil].
 
+ ^ self new openOnHostNamed: hostName port: portNumber!
- ^ (self openOnHost: serverIP port: portNumber)
- hostName: hostName;
- yourself
- !

Item was changed:
  ----- Method: ProtocolClient>>openOnHost:port: (in category 'private') -----
  openOnHost: hostIP port: portNumber
+ "open a connection to a specific port on a host for which we have the IP number.
+ We handle any login if the user and password are set"
  self host: hostIP.
  self port: portNumber.
  self ensureConnection!

Item was added:
+ ----- Method: ProtocolClient>>openOnHostNamed: (in category 'private') -----
+ openOnHostNamed: hostNameAndPort
+ "If the hostname uses the colon syntax to express a certain port number
+ we use that instead of the default port number."
+
+ | thing hostName port |
+ "derive a host name and port number"
+ thing := hostNameAndPort splitBy: ':'.
+ hostName := thing first.
+ port := (thing at: 2 ifAbsent: [self defaultPortNumber]) asInteger.
+
+ ^self openOnHostNamed: hostName port: port
+ !

Item was added:
+ ----- Method: ProtocolClient>>openOnHostNamed:port: (in category 'private') -----
+ openOnHostNamed: hostName port: portNumber
+ "open a connection to a specific port on a server"
+ | serverIP |
+ serverIP := NetNameResolver addressForName: hostName timeout: 20.
+ self
+ hostName: hostName;
+ openOnHost: serverIP port: portNumber!

Item was changed:
  ----- Method: SMTPClient class>>deliverMailFrom:to:text:usingServer: (in category 'sending mail') -----
  deliverMailFrom: fromAddress to: recipientList text: messageText usingServer: serverName
+ "Deliver a single email to a list of users and then close the connection - for delivering multiple messages, it is best to create a single connection and send all mail over it.
+ The serverName can include the port number - simply append ':587' for example to over ride the default port number.
+ No user name or password is used in this method; see deliverMailFrom:to:text:usingServer:userName:password: for more.
+ NOTE: the recipient list should be a collection of simple internet style addresses -- no '<>' or '()' stuff"
- "Deliver a single email to a list of users and then close the connection.  For delivering multiple messages, it is best to create a single connection and send all mail over it.  NOTE: the recipient list should be a collection of simple internet style addresses -- no '<>' or '()' stuff"
 
+ self deliverMailFrom: fromAddress to: recipientList text: messageText usingServer: serverName userName: nil password: nil
- | smtpClient |
- smtpClient := self openOnHostNamed: serverName.
- [smtpClient mailFrom: fromAddress to: recipientList text: messageText.
- smtpClient quit]
- ensure: [smtpClient close]
  !

Item was added:
+ ----- Method: SMTPClient class>>deliverMailFrom:to:text:usingServer:userName:password: (in category 'sending mail') -----
+ deliverMailFrom: fromAddress to: recipientList text: messageText usingServer: serverName userName: uNameString password: pwdString
+ "Deliver a single email to a list of users and then close the connection - for delivering multiple messages, it is best to create a single connection and send all mail over it.
+ The serverName can include the port number - simply append ':587' for example to over ride the default port number.
+ If uNameString or pwdString are non-nil, set the uid/pwd for the client. It is inadvisable to try setting a uid and not a pwd, or indeed vice versa.
+ NOTE: the recipient list should be a collection of simple internet style addresses -- no '<>' or '()' stuff"
+
+ | smtpClient |
+ smtpClient := self new.
+
+ uNameString ifNotNil:[smtpClient user: uNameString].
+ pwdString ifNotNil:[smtpClient password: pwdString].
+ smtpClient openOnHostNamed: serverName.
+ [smtpClient mailFrom: fromAddress to: recipientList text: messageText.
+ smtpClient quit]
+ ensure: [smtpClient close]
+ !

Item was removed:
- ----- Method: SMTPClient class>>openOnHost:port: (in category 'instance creation') -----
- openOnHost: hostIP port: portNumber
-
- | client |
- client := super openOnHost: hostIP port: portNumber.
- client initiateSession.
- ^client!