sumim #1093(2007/07/19 08:11 GMT) [ Smalltalk ] Rating0/0=0.00
Squeak Smalltalk で。 テンプレートは指定のままですが、差し込みデータは Smalltalk のコードとして意味を持つよう変更しました。 ----差し込みデータ (data.txt)---- { #from -> 'from@example.org'. #to -> 'to@example.org'. #name -> 'どう書く'. #fromname -> '管理者'. #url -> 'http://ja.doukaku.org/' } ----差し込みデータ (data.txt) ----
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| template data tempArray fields elems mail encoding out tempFile dataFile | fields := #(from to name fromname url). tempFile := FileStream fileNamed: 'template.txt'. template := tempFile contents. tempFile close. dataFile := FileStream fileNamed: 'data.txt'. data := (Compiler evaluate: dataFile contents) as: Dictionary. tempArray := template findBetweenSubStrs: #('[[' ']]'). fields doWithIndex: [:fieldName :idx | tempArray replaceAll: fieldName with: '{', idx printString, '}']. template := tempArray inject: '' into: [:result :each | result, each]. elems := fields collect: [:field | data at: field]. encoding := 'iso-2022-jp'. mail := MailMessage from: (template format: elems). mail setField: 'Message-ID' toString: ('<{1}.{2}@{3}>' format: {DateAndTime now asSeconds. mail hash. mail from copyAfter: $@}). mail setField: 'MIME-Version' toString: '1.0'. mail setField: 'Content-Type' toString: ('{1}; charset="{2}"' format: {mail body contentType. encoding}). mail setField: 'Content-Transfer-Encoding' toString: '7bit'. mail setField: 'Date' toString: ('{1}, {2} {3} {4}' format: {Date today weekday first: 3. Date today. Time now print24. DateAndTime now printString last: 6}). mail subject isOctetString ifFalse: [ | subject | subject := mail subject convertToEncoding: encoding. subject := (Base64MimeConverter mimeEncode: subject readStream) contents. mail setField: 'subject' toString: ('=?{1}?{2}?=' format: {encoding. subject})]. mail regenerateText. out := FileStream newFileNamed: 'out.txt'. out converter: (TextConverter defaultConverterClassForEncoding: encoding) new. out nextPutAll: mail text. out edit
Rating0/0=0.00-0+
[ reply ]
sumim
#1093()
[
Smalltalk
]
Rating0/0=0.00
Squeak Smalltalk で。 テンプレートは指定のままですが、差し込みデータは Smalltalk のコードとして意味を持つよう変更しました。 ----差し込みデータ (data.txt)---- { #from -> 'from@example.org'. #to -> 'to@example.org'. #name -> 'どう書く'. #fromname -> '管理者'. #url -> 'http://ja.doukaku.org/' } ----差し込みデータ (data.txt) ----| template data tempArray fields elems mail encoding out tempFile dataFile | fields := #(from to name fromname url). tempFile := FileStream fileNamed: 'template.txt'. template := tempFile contents. tempFile close. dataFile := FileStream fileNamed: 'data.txt'. data := (Compiler evaluate: dataFile contents) as: Dictionary. tempArray := template findBetweenSubStrs: #('[[' ']]'). fields doWithIndex: [:fieldName :idx | tempArray replaceAll: fieldName with: '{', idx printString, '}']. template := tempArray inject: '' into: [:result :each | result, each]. elems := fields collect: [:field | data at: field]. encoding := 'iso-2022-jp'. mail := MailMessage from: (template format: elems). mail setField: 'Message-ID' toString: ('<{1}.{2}@{3}>' format: {DateAndTime now asSeconds. mail hash. mail from copyAfter: $@}). mail setField: 'MIME-Version' toString: '1.0'. mail setField: 'Content-Type' toString: ('{1}; charset="{2}"' format: {mail body contentType. encoding}). mail setField: 'Content-Transfer-Encoding' toString: '7bit'. mail setField: 'Date' toString: ('{1}, {2} {3} {4}' format: {Date today weekday first: 3. Date today. Time now print24. DateAndTime now printString last: 6}). mail subject isOctetString ifFalse: [ | subject | subject := mail subject convertToEncoding: encoding. subject := (Base64MimeConverter mimeEncode: subject readStream) contents. mail setField: 'subject' toString: ('=?{1}?{2}?=' format: {encoding. subject})]. mail regenerateText. out := FileStream newFileNamed: 'out.txt'. out converter: (TextConverter defaultConverterClassForEncoding: encoding) new. out nextPutAll: mail text. out editRating0/0=0.00-0+
[ reply ]