Patrick Rein uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-pre.747.mcz ==================== Summary ==================== Name: Collections-pre.747 Author: pre Time: 20 April 2017, 11:37:10.168994 am UUID: 6fe02314-e789-064a-b678-0caec3506aac Ancestors: Collections-eem.746 changes decoding of mime headers to decode directly to squeak encoding =============== Diff against Collections-eem.746 =============== Item was changed: ----- Method: String>>decodeMimeHeader (in category 'internet') ----- decodeMimeHeader "See RFC 2047, MIME Part Three: Message Header Extension for Non-ASCII + Text and RFC 1342. Text containing non-ASCII characters is encoded by the sequence - Text. Text containing non-ASCII characters is encoded by the sequence =?character-set?encoding?encoded-text?= Encoding is Q (quoted printable) or B (Base64), handled by Base64MimeConverter / RFC2047MimeConverter. Thanks to Yokokawa-san, it works in m17n package. Try the following: '=?ISO-2022-JP?B?U1dJS0lQT1AvGyRCPUJDKyVpJXMlQRsoQi8=?= =?ISO-2022-JP?B?GyRCJVElRiUjJSobKEIoUGF0aW8p?=' decodeMimeHeader. " | input output temp charset decoder encodedStream encoding pos | input := ReadStream on: self. output := WriteStream on: String new. [output nextPutAll: (input upTo: $=). "ASCII Text" input atEnd] whileFalse: [(temp := input next) = $? ifTrue: [charset := input upTo: $?. encoding := (input upTo: $?) asUppercase. temp := input upTo: $?. input next. "Skip final =" (charset isNil or: [charset size = 0]) ifTrue: [charset := 'LATIN-1']. + encodedStream := WriteStream on: String new. - encodedStream := MultiByteBinaryOrTextStream on: String new encoding: charset. decoder := encoding = 'B' ifTrue: [Base64MimeConverter new] ifFalse: [RFC2047MimeConverter new]. decoder mimeStream: (ReadStream on: temp); dataStream: encodedStream; mimeDecode. + + output nextPutAll: (MultiByteBinaryOrTextStream with: encodedStream contents encoding: charset) contents. - output nextPutAll: encodedStream reset contents. pos := input position. input skipSeparators. "Delete spaces if followed by =" input peek = $= ifFalse: [input position: pos]] ifFalse: [output nextPut: $=; nextPut: temp]]. ^ output contents! |
On Thu, 20 Apr 2017, [hidden email] wrote:
> Patrick Rein uploaded a new version of Collections to project The Trunk: > http://source.squeak.org/trunk/Collections-pre.747.mcz > > ==================== Summary ==================== > > Name: Collections-pre.747 > Author: pre > Time: 20 April 2017, 11:37:10.168994 am > UUID: 6fe02314-e789-064a-b678-0caec3506aac > Ancestors: Collections-eem.746 > > changes decoding of mime headers to decode directly to squeak encoding > > =============== Diff against Collections-eem.746 =============== > > Item was changed: > ----- Method: String>>decodeMimeHeader (in category 'internet') ----- > decodeMimeHeader > "See RFC 2047, MIME Part Three: Message Header Extension for Non-ASCII > + Text and RFC 1342. Text containing non-ASCII characters is encoded by the sequence > - Text. Text containing non-ASCII characters is encoded by the sequence > =?character-set?encoding?encoded-text?= > Encoding is Q (quoted printable) or B (Base64), handled by > Base64MimeConverter / RFC2047MimeConverter. > > Thanks to Yokokawa-san, it works in m17n package. Try the following: > > '=?ISO-2022-JP?B?U1dJS0lQT1AvGyRCPUJDKyVpJXMlQRsoQi8=?= =?ISO-2022-JP?B?GyRCJVElRiUjJSobKEIoUGF0aW8p?=' decodeMimeHeader. > " > | input output temp charset decoder encodedStream encoding pos | > input := ReadStream on: self. > output := WriteStream on: String new. > [output > nextPutAll: (input upTo: $=). > "ASCII Text" > input atEnd] > whileFalse: [(temp := input next) = $? > ifTrue: [charset := input upTo: $?. > encoding := (input upTo: $?) asUppercase. > temp := input upTo: $?. > input next. > "Skip final =" > (charset isNil or: [charset size = 0]) ifTrue: [charset := 'LATIN-1']. > + encodedStream := WriteStream on: String new. Creating a WriteStream on an empty string is just a waste, since it'll have to allocate another string on the first write. #on: will always create an empty stream, the argument will be the initial buffer. > - encodedStream := MultiByteBinaryOrTextStream on: String new encoding: charset. > decoder := encoding = 'B' > ifTrue: [Base64MimeConverter new] > ifFalse: [RFC2047MimeConverter new]. > decoder > mimeStream: (ReadStream on: temp); > dataStream: encodedStream; > mimeDecode. > + > + output nextPutAll: (MultiByteBinaryOrTextStream with: encodedStream contents encoding: charset) contents. The above conversion should be done without creating a MultiByteBinaryOrTextStream. Levente P.S.: The whole method could use some refactoring. > - output nextPutAll: encodedStream reset contents. > pos := input position. > input skipSeparators. > "Delete spaces if followed by =" > input peek = $= > ifFalse: [input position: pos]] > ifFalse: [output nextPut: $=; > nextPut: temp]]. > ^ output contents! |
Free forum by Nabble | Edit this page |