Patrick Rein uploaded a new version of Network to project The Trunk:
http://source.squeak.org/trunk/Network-pre.196.mcz ==================== Summary ==================== Name: Network-pre.196 Author: pre Time: 12 May 2017, 5:37:22.575874 pm UUID: f3fc17ec-f996-494d-a2b0-d3d52b410d64 Ancestors: Network-pre.195 Adds several supporting features for email handling including a message for creating a reply to a message, dealing with charsets in MIME documents, and a rfc 822 compliant printing of DateAndTime objects =============== Diff against Network-pre.195 =============== Item was added: + ----- Method: DateAndTime>>asMailMessageString (in category '*Network-Url') ----- + asMailMessageString + "According to RFC 822: https://tools.ietf.org/html/rfc822#section-5" + + | result | + result := WriteStream on: (String new: 30). + + result + nextPutAll: self dayOfWeekAbbreviation; + nextPut: $,; + space; + nextPutAll: (self dayOfMonth asString padded: #left to: 2 with: $0); + space; + nextPutAll: self monthAbbreviation; + space; + nextPutAll: self year asString; + space. + + self printHMSOn: result. + + result space. + + result + nextPutAll: (self offset isNegative ifTrue: ['-'] ifFalse: ['+']); + nextPutAll: (self offset abs hours asString padded: #left to: 2 with: $0); + nextPutAll: (self offset abs minutes asString padded: #left to: 2 with: $0). + + ^ result contents! Item was added: + ----- Method: MIMEDocument>>charset (in category 'accessing') ----- + charset + + ^ self parameterNamed: 'charset' ifAbsent: ['us-ascii']! Item was added: + ----- Method: MIMEDocument>>charset: (in category 'accessing') ----- + charset: aString + + ^ parameters at: 'charset' put: aString! Item was added: + ----- Method: MailMessage class>>replyFor: (in category 'instance creation') ----- + replyFor: aMailMessage + + | replyReceiver replySubject references | + replyReceiver := (aMailMessage + fieldNamed: 'reply-to' + ifAbsent: [aMailMessage + fieldNamed: 'from' + ifAbsent: [self error: 'there is a field missing in the original message']]) mainValue. + + replySubject := (aMailMessage subject beginsWith: 'Re:') + ifTrue: [aMailMessage subject] + ifFalse: ['Re: ' , aMailMessage subject]. + + references := (aMailMessage hasFieldNamed: 'references') + ifTrue: [(aMailMessage fieldNamed: 'references' ifAbsent: [self error: 'Something changed the mail between the check and now']) mainValue , ', ' , aMailMessage messageId] + ifFalse: [aMailMessage messageId]. + + ^ self empty + to: replyReceiver; + subject: replySubject; + setField: 'in-reply-to' toString: aMailMessage messageId; + setField: 'references' toString: references; + yourself + ! Item was added: + ----- Method: MailMessage>>dateTime: (in category 'access') ----- + dateTime: aDateTime + + self setField: 'date' toString: aDateTime asMailMessageString! Item was changed: + ----- Method: MailMessage>>from: (in category 'access') ----- + from: aString - ----- Method: MailMessage>>from: (in category 'initialize-release') ----- - from: aString - "Parse aString to initialize myself." - - | parseStream contentType bodyText contentTransferEncoding | - - text := aString withoutTrailingBlanks, String cr, String cr. - parseStream := ReadStream on: text. - contentType := 'text/plain'. - contentTransferEncoding := nil. - fields := Dictionary new. - - "Extract information out of the header fields" - self fieldsFrom: parseStream do: - [:fName :fValue | - "NB: fName is all lowercase" - - fName = 'content-type' ifTrue: [contentType := fValue asLowercase]. - fName = 'content-transfer-encoding' ifTrue: [contentTransferEncoding := fValue asLowercase]. - - (fields at: fName ifAbsentPut: [OrderedCollection new: 1]) - add: (MIMEHeaderValue forField: fName fromString: fValue)]. - - "Extract the body of the message" - bodyText := parseStream upToEnd. - contentTransferEncoding = 'base64' ifTrue: [ - bodyText := Base64MimeConverter mimeDecodeToChars: (ReadStream on: bodyText). - bodyText := bodyText contents]. - contentTransferEncoding = 'quoted-printable' ifTrue: [ - bodyText := bodyText decodeQuotedPrintable]. + | sanitizedMailAddress | + sanitizedMailAddress := (MailAddressParser addressesIn: aString) first. + ^self setField: 'from' toString: sanitizedMailAddress! - body := MIMEDocument contentType: contentType content: bodyText! Item was added: + ----- Method: MailMessage>>messageId: (in category 'access') ----- + messageId: aString + + ^ self setField: 'message-id' toString: aString! Item was added: + ----- Method: MailMessage>>to: (in category 'access') ----- + to: aString + + | sanitizedMailAddresses | + sanitizedMailAddresses := (MailAddressParser addressesIn: aString) asSet asArray. + ^self setField: 'to' toString: (sanitizedMailAddresses joinSeparatedBy: ', ')! |
Free forum by Nabble | Edit this page |