]> gitweb.factorcode.org Git - factor.git/blob - extra/mason/email/email.factor
55edfcb30bf55102ed92ff82f8ddce223420c5a5
[factor.git] / extra / mason / email / email.factor
1 ! Copyright (C) 2008, 2009 Eduardo Cavazos, Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel namespaces accessors combinators make smtp debugger
4 prettyprint io io.streams.string io.encodings.utf8 io.files io.sockets
5 mason.common mason.platform mason.config ;
6 IN: mason.email
7
8 : prefix-subject ( str -- str' )
9     [ "mason on " % platform % ": " % % ] "" make ;
10
11 : email-status ( body content-type subject -- )
12     <email>
13         builder-from get >>from
14         builder-recipients get >>to
15         swap >>content-type
16         swap prefix-subject >>subject
17         swap >>body
18     send-email ;
19
20 : subject ( -- str )
21     status get {
22         { status-clean [ "clean" ] }
23         { status-dirty [ "dirty" ] }
24         { status-error [ "error" ] }
25     } case ;
26
27 : email-report ( -- )
28     "report" utf8 file-contents "text/html" subject email-status ;
29
30 : email-error ( error callstack -- )
31     [
32         "Fatal error on " write host-name print nl
33         [ error. ] [ callstack. ] bi*
34     ] with-string-writer "text/plain" "fatal error"
35     email-status ;