REBOL [ Title: "Recipe to email" Purpose: {Render one recipe into a text string suitable for emailing.} ] ;; [---------------------------------------------------------------------------] ;; [ If you have installed REBOL, then the file user.r is loaded automaticlly. ] ;; [ Otherwise, depending on circumstances, you might have to find that file ] ;; [ and copy it to the folder where you are running this program. ] ;; [---------------------------------------------------------------------------] do %user.r ;; [---------------------------------------------------------------------------] ;; [ Put your own set of email addresses here. ] ;; [---------------------------------------------------------------------------] EMAIL-ADDRESSES: [ john-doe@gmail.com ] if not FILE-ID: request-file/only [ alert "No file requested." quit ] EMAIL-PAGE: "" WS-INGREDIENT-LIST: "" if not attempt [do load FILE-ID] [ alert "Recipe file format is not correct" quit ] if not value? 'RECIPE-NAME [ alert "RECIPE-NAME is not defined in the file" quit ] if not value? 'RECIPE-SOURCE [ alert "RECIPE-SOURCE is not defined in the file" quit ] if not value? 'RECIPE-INGREDIENTS [ alert "RECIPE-INGREDIENTS is not defined in the file" quit ] if not value? 'RECIPE-PROCEDURE [ alert "RECIPE-PROCEDURE is not defined in the file" quit ] if not value? 'RECIPE-NOTES [ alert "RECIPE-NOTES is not defined in the file" quit ] WS-INGREDIENT-LIST: copy "" foreach INGREDIENT-BLOCK RECIPE-INGREDIENTS [ foreach [INGREDIENT QUANTITY] INGREDIENT-BLOCK [ append WS-INGREDIENT-LIST rejoin [ INGREDIENT ", " QUANTITY newline ] ] ] append EMAIL-PAGE rejoin [ RECIPE-NAME newline newline ] append EMAIL-PAGE rejoin [ "Ingredients:" newline newline ] append EMAIL-PAGE rejoin [ WS-INGREDIENT-LIST newline ] append EMAIL-PAGE rejoin [ "Procedure:" newline ] append EMAIL-PAGE rejoin [ RECIPE-PROCEDURE newline ] append EMAIL-PAGE rejoin [ "Notes:" newline ] SEND-MAIL: does [ if not MAIL-ADDR/text [ alert "No address selected." exit ] WS-ADDRESS: to-email trim MAIL-ADDR/text SEND WS-ADDRESS MAIL-TEXT/text alert "Sent." ] view center-face layout [ across MAIL-ADDR: drop-down 400 data EMAIL-ADDRESSES rows 20 return MAIL-TEXT: area 400x600 EMAIL-PAGE return button "Send" [SEND-MAIL] button "Quit" [quit] button "Debug" [halt] ]