Extended WAEmailMessage to include headers

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

Extended WAEmailMessage to include headers

Udo Schneider
All,

I just went through the process of sending UTF-8 encoded mail from Seaside 3.0. Doing that I discovered that you can set Mail Headers for WAEMailMessage inctances but that those headers are not passed to the underlying Platform (at least on Pharo). I extended #plainMessage to include those headers and violà .. it works:

WAEmailMessageplainMessage
        ^ String streamContents:
                [ :stream |
                self headers keysAndValuesDo:
                        [ :key :value |
                        stream
                                nextPutAll: key greaseString;
                                nextPutAll: ': ';
                                nextPutAll: value greaseString;
                                nextPut: Character cr ].
                self
                        renderAddress: self from
                        withHeader: 'From: '
                        on: stream.
                self to do:
                        [ :each |
                        self
                                renderAddress: each
                                withHeader: 'To: '
                                on: stream ].
                self cc do:
                        [ :each |
                        self
                                renderAddress: each
                                withHeader: 'Cc: '
                                on: stream ].
                self bcc do:
                        [ :each |
                        self
                                renderAddress: each
                                withHeader: 'Bcc: '
                                on: stream ].
                stream
                        nextPutAll: 'Subject: ';
                        nextPutAll: self subject;
                        nextPut: Character cr;
                        nextPut: Character cr.
                self body isNil ifFalse: [ stream nextPutAll: self body greaseString ] ]

I can now send UTF-8 encoded mails using:

(WAEmailMessage from: self mailFrom toAll: self mailRecipients subject: self mailSubject)
        addBcc: self mailBccRecipient;
        headerAt: 'MIME-Version' put: '1.0';
        headerAt: 'Content-type' put: 'text/plain; charset=UTF-8';
        body: ((GRCodec forEncoding: 'utf-8') encode: self mailBody);
        send.

Is this a valid approach or did I screw up entirly (still a bad feeling modyfing "base" classes).

Best Regards,

Udo


_______________________________________________
seaside-dev mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev
Reply | Threaded
Open this post in threaded view
|

Re: Extended WAEmailMessage to include headers

Philippe Marschall
2010/11/3 Udo Schneider <[hidden email]>:

> All,
>
> I just went through the process of sending UTF-8 encoded mail from Seaside 3.0. Doing that I discovered that you can set Mail Headers for WAEMailMessage inctances but that those headers are not passed to the underlying Platform (at least on Pharo). I extended #plainMessage to include those headers and violà .. it works:
>
> WAEmailMessageplainMessage
>        ^ String streamContents:
>                [ :stream |
>                self headers keysAndValuesDo:
>                        [ :key :value |
>                        stream
>                                nextPutAll: key greaseString;
>                                nextPutAll: ': ';
>                                nextPutAll: value greaseString;
>                                nextPut: Character cr ].
>                self
>                        renderAddress: self from
>                        withHeader: 'From: '
>                        on: stream.
>                self to do:
>                        [ :each |
>                        self
>                                renderAddress: each
>                                withHeader: 'To: '
>                                on: stream ].
>                self cc do:
>                        [ :each |
>                        self
>                                renderAddress: each
>                                withHeader: 'Cc: '
>                                on: stream ].
>                self bcc do:
>                        [ :each |
>                        self
>                                renderAddress: each
>                                withHeader: 'Bcc: '
>                                on: stream ].
>                stream
>                        nextPutAll: 'Subject: ';
>                        nextPutAll: self subject;
>                        nextPut: Character cr;
>                        nextPut: Character cr.
>                self body isNil ifFalse: [ stream nextPutAll: self body greaseString ] ]
>
> I can now send UTF-8 encoded mails using:
>
> (WAEmailMessage from: self mailFrom toAll: self mailRecipients subject: self mailSubject)
>        addBcc: self mailBccRecipient;
>        headerAt: 'MIME-Version' put: '1.0';
>        headerAt: 'Content-type' put: 'text/plain; charset=UTF-8';
>        body: ((GRCodec forEncoding: 'utf-8') encode: self mailBody);
>        send.
>
> Is this a valid approach or did I screw up entirly (still a bad feeling modyfing "base" classes).
The headers should get passed, see WAEmailMessageTest >> #testHeaders.
The #plainMessage im my image does this except at the end instead of
the start. I'm a bit confused, how did your #plainMessage look before?

plainMessage
        ^ String streamContents: [ :stream |
                self
                        renderAddress: self from
                        withHeader: 'From: '
                        on: stream.
                self to do: [ :each |
                        self
                                renderAddress: each
                                withHeader: 'To: '
                                on: stream ].
                self cc do: [ :each |
                        self
                                renderAddress: each
                                withHeader: 'Cc: '
                                on: stream ].
                self bcc do: [ :each |
                        self
                                renderAddress: each
                                withHeader: 'Bcc: '
                                on: stream ].
                stream
                        nextPutAll: 'Subject: ';
                        nextPutAll: self subject;
                        nextPut: Character cr.
                       
                self headers keysAndValuesDo: [ :key :value |
                        stream
                                nextPutAll: key greaseString; nextPut: $:; nextPut: Character space;
                                nextPutAll: value greaseString; nextPut: Character cr].
               
                stream nextPut: Character cr. "let body start"
               
                self body isNil ifFalse: [ stream nextPutAll: self body greaseString ] ]

Cheers
Philippe

_______________________________________________
seaside-dev mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev
Reply | Threaded
Open this post in threaded view
|

Re: Extended WAEmailMessage to include headers

Udo Schneider

On 06.11.2010, at 19:09, Philippe Marschall wrote:
>
> The headers should get passed, see WAEmailMessageTest >> #testHeaders.
> The #plainMessage im my image does this except at the end instead of
> the start. I'm a bit confused, how did your #plainMessage look before?

The methods is as following in my base image:
plainMessage
        ^ String streamContents:
                [ :stream |
                self
                        renderAddress: self from
                        withHeader: 'From: '
                        on: stream.
                self to do:
                        [ :each |
                        self
                                renderAddress: each
                                withHeader: 'To: '
                                on: stream ].
                self cc do:
                        [ :each |
                        self
                                renderAddress: each
                                withHeader: 'Cc: '
                                on: stream ].
                self bcc do:
                        [ :each |
                        self
                                renderAddress: each
                                withHeader: 'Bcc: '
                                on: stream ].
                stream
                        nextPutAll: 'Subject: ';
                        nextPutAll: self subject;
                        nextPut: Character cr;
                        nextPut: Character cr.
                self body isNil ifFalse: [ stream nextPutAll: self body greaseString ] ]

The package is Seaside-Email-lr.15. Just checked that your Seaside-Email-pmm.19 package is indeed fixed. Seems to be a problem that the Metacello config still loads v.15. I just checked this with

Gofer new
        squeaksource: 'MetacelloRepository';
        package: 'ConfigurationOfSeaside';
        load.
(Smalltalk at: #ConfigurationOfSeaside) project latestVersion load: #( 'Seaside 3.0' 'Magritte2' ).

Sorry for the hassle.

CU,

Udo

_______________________________________________
seaside-dev mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev
Reply | Threaded
Open this post in threaded view
|

Re: Extended WAEmailMessage to include headers

Philippe Marschall
2010/11/6 Udo Schneider <[hidden email]>:

>
> On 06.11.2010, at 19:09, Philippe Marschall wrote:
>>
>> The headers should get passed, see WAEmailMessageTest >> #testHeaders.
>> The #plainMessage im my image does this except at the end instead of
>> the start. I'm a bit confused, how did your #plainMessage look before?
>
> The methods is as following in my base image:
> plainMessage
>        ^ String streamContents:
>                [ :stream |
>                self
>                        renderAddress: self from
>                        withHeader: 'From: '
>                        on: stream.
>                self to do:
>                        [ :each |
>                        self
>                                renderAddress: each
>                                withHeader: 'To: '
>                                on: stream ].
>                self cc do:
>                        [ :each |
>                        self
>                                renderAddress: each
>                                withHeader: 'Cc: '
>                                on: stream ].
>                self bcc do:
>                        [ :each |
>                        self
>                                renderAddress: each
>                                withHeader: 'Bcc: '
>                                on: stream ].
>                stream
>                        nextPutAll: 'Subject: ';
>                        nextPutAll: self subject;
>                        nextPut: Character cr;
>                        nextPut: Character cr.
>                self body isNil ifFalse: [ stream nextPutAll: self body greaseString ] ]
>
> The package is Seaside-Email-lr.15. Just checked that your Seaside-Email-pmm.19 package is indeed fixed. Seems to be a problem that the Metacello config still loads v.15. I just checked this with
>
> Gofer new
>        squeaksource: 'MetacelloRepository';
>        package: 'ConfigurationOfSeaside';
>        load.
> (Smalltalk at: #ConfigurationOfSeaside) project latestVersion load: #( 'Seaside 3.0' 'Magritte2' ).
Hm, AFAIK Dale move ConfigurationOfSeaside to Seaside30.

> Sorry for the hassle.

Don't worry, we're happy people are using it.

Cheers
Philippe

_______________________________________________
seaside-dev mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev
Reply | Threaded
Open this post in threaded view
|

Re: Extended WAEmailMessage to include headers

Dale Henrichs
On 11/07/2010 05:24 AM, Philippe Marschall wrote:

> 2010/11/6 Udo Schneider<[hidden email]>:
>>
>> On 06.11.2010, at 19:09, Philippe Marschall wrote:
>>>
>>> The headers should get passed, see WAEmailMessageTest>>  #testHeaders.
>>> The #plainMessage im my image does this except at the end instead of
>>> the start. I'm a bit confused, how did your #plainMessage look before?
>>
>> The methods is as following in my base image:
>> plainMessage
>>         ^ String streamContents:
>>                 [ :stream |
>>                 self
>>                         renderAddress: self from
>>                         withHeader: 'From: '
>>                         on: stream.
>>                 self to do:
>>                         [ :each |
>>                         self
>>                                 renderAddress: each
>>                                 withHeader: 'To: '
>>                                 on: stream ].
>>                 self cc do:
>>                         [ :each |
>>                         self
>>                                 renderAddress: each
>>                                 withHeader: 'Cc: '
>>                                 on: stream ].
>>                 self bcc do:
>>                         [ :each |
>>                         self
>>                                 renderAddress: each
>>                                 withHeader: 'Bcc: '
>>                                 on: stream ].
>>                 stream
>>                         nextPutAll: 'Subject: ';
>>                         nextPutAll: self subject;
>>                         nextPut: Character cr;
>>                         nextPut: Character cr.
>>                 self body isNil ifFalse: [ stream nextPutAll: self body greaseString ] ]
>>
>> The package is Seaside-Email-lr.15. Just checked that your Seaside-Email-pmm.19 package is indeed fixed. Seems to be a problem that the Metacello config still loads v.15. I just checked this with
>>
>> Gofer new
>>         squeaksource: 'MetacelloRepository';
>>         package: 'ConfigurationOfSeaside';
>>         load.
>> (Smalltalk at: #ConfigurationOfSeaside) project latestVersion load: #( 'Seaside 3.0' 'Magritte2' ).
>
> Hm, AFAIK Dale move ConfigurationOfSeaside to Seaside30.
>
>> Sorry for the hassle.
>
> Don't worry, we're happy people are using it.
>
> Cheers
> Philippe

I'm hoping to get all of the Seaside configs updated this week (lets all
cross our fingers:)

Dale
_______________________________________________
seaside-dev mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev