# loaddefs link d_QNial_mine 'email - ARED daemon program.ndf' # www.BillHowell.ca 27Jan2020 initial split out of 'email - split Thunderbird email folder.ndf' # 28Jan2020 currently uses Thunderbird email program, probably bettere to convert to http://www.mutt.org f_emailDaemon := 'email - ARED daemon program.ndf' ; loaddefs_start f_emailDaemon ; #************ # List of operators, generated with : # $ cat "$d_Qndfs""email - ARED daemon program.ndf" | grep "^#]" | sed 's/^#\]/ /' # test_inquiry IS - create and send a test email to the daemon daemonEml_to_anonymous IS - forward "Anonymous Receiver Email Daemon" (ARED) emails emailSplit_daemonInbox IS - for daemon, split inbox into [good, badd] email folders, then process "good" daemon_run IS - continuous, real-time contol loop for ARED daemon #*********** # Setup (kind of like header info) flag_break := l ; flag_debug := o ; # Reminder of debug setup... # IF flag_break = l THEN Break ; ENDIF ; loaddefs '/home/bill/PROJECTS/Qnial/setup.ndf' loaddefs link d_QNial_mine 'email - split Thunderbird email folder.ndf' ; loaddefs link d_QNial_secure 'email - ARED daemon WCCI2020.ndf' ; loaddefs link d_QNial_secure 'email - ARED daemon Hussar.ndf' ; # daemon stuff ; sleep_time := 300 ; % seconds delay after daemon sends responses to emails ; email_filter_phrase := "email_filter ; mime_expand_flag := o ; % don't expand mime, as keyStrs are only in the "Subject" of the email ; massEmailRemove_flag := o ; #*********************************************** #] test_inquiry IS - create and send a test email to the daemon # 21Jan2020 write 'loading test_inquiry' ; #IF flag_break = l THEN Break ; ENDIF ; # loaddefs link d_QNial_mine 'email - ARED daemon program.ndf' # test_inquiry test_inquiry IS { LOCAL finn froms CCins subject Date attachment body i_key Toers CCads CCers cmd ; NONLOCAL p_emlOner daemon keyStrsALL TosList CCsList ; % ; % attach an email file (just one that is on file as p_emlOne) ; attachment := '/home/bill/SWAPPER/Website/Cool stuff/Harry S Dent - Total debt vs GDP Western nations 2013.jpg' ; % ; % information from the contacts data ; %i_key := find subject keyStrsALL ; Toers := 'IEEE WCCI 2020 HELP daemon (ARED) ' ; subject := 'IEEE WCCI 2020 HELP : leftover' ; CCads := ' ' ; body := link 'This is a test message for the "Anonymous Recipient Email Daemon" (AERD) :%0D%0A      "' daemon '".%0D%0A%0D%0ASee the attachment. Note the time delay as this is run manually once or twice a day, but only during active periods. ' ; % ; % forward email ; host link 'thunderbird -compose "to=' Toers ',subject=' subject ',cc=' CCads ',body=' body ',attachment=' attachment '" ' ; send_Thunderbird daemon ; } #*********************************************** #] daemonEml_to_anonymous IS - forward "Anonymous Receiver Email Daemon" (ARED) emails # 16Jan2020 Adapted from : # "$d_QNial_mine""email - send many individualised.ndf" # "$d_bin""email - create auto.sh" # must TURN OFF spellcheck!! (ARED) # BEFORE attaching an email, leading whitespace lines must be removed, and it must have the extension ".eml", not ".txt"! ; write 'loading daemonEml_to_anonymous' ; # IF flag_break = l THEN Break ; ENDIF ; # host link 'cp "' (link d_log 'emlOner for tests.txt') '" "' (link d_QNial_temp 'single email.eml') '" ' # loaddefs link d_QNial_mine 'email - ARED daemon program.ndf' # daemonEml_to_anonymous - must have put p_emlOner in d_QNial_temp (see host cmd just above) daemonEml_to_anonymous IS { LOCAL finn froms CCins subject Date attachment body i_key Toers CCads CCers cmd ; NONLOCAL p_emlOner daemon keyStrsALL TosList CCsList ; % ; % information from the inquiry email, the following expect lines of the email to be in the order indicated ; finn := open p_emlOner "r ; froms := clean_emlAddress (find_emailHdr_item finn 'From: ' ) ; CCins := clean_emlAddress (find_emailHdr_item finn 'CC: ' ) ; subject := clean_emlAddress (find_emailHdr_item finn 'Subject: ') ; Date := clean_emlAddress (find_emailHdr_item finn 'Date: ' ) ; attachment := p_emlOner ; close finn ; % ; % information from the contacts data ; i_key := find subject keyStrsALL ; IF (= 'testing' (last towords1 subject)) THEN Toers := froms ; ELSE Toers := clean_emlAddress (i_key pick TosList ) ; ENDIF ; CCads := clean_emlAddress (i_key pick CCsList ) ; % ; % forward email ; body := link 'This message has been forwarded by the "Anonymous Recipient Email Daemon" (AERD) :%0D%0A      "' daemon '".%0D%0A%0D%0ASee the attachment. Note the time delay as this is run manually once or twice a day, but only during active periods. ' ; host link 'thunderbird -compose "to=' Toers ',subject=' subject ',cc=' CCads ',body=' body ',attachment=' attachment '" ' ; sleep 1 ; send_Thunderbird daemon ; % ; % confirmation to sender that the email has been forwarded ; subject := link 'RE: ' subject ; body := link 'Your email of "' Date '" has been forwarded to the contacts applicable to the "Subject:" line FAQ.%0D%0ANote the time delay from the time that you sent your email as this daemon is run manually only once or twice a day during active periods, rather than running in real time on my ssh server. ' ; host link 'thunderbird -compose "to=' froms ',subject=' subject ',cc=' CCins ',body=' body ',attachment=' attachment '" ' ; sleep 1 ; send_Thunderbird daemon ; } # old code # cmd := link 'thunderbird -compose "from=IEEE WCCI 2020 HELP daemon (ARED) ,to=' Toers ',subject=' subject ',cc=' CCads ',body=' body ',attachment=' attachment '" ' ; #*********************************************** #] emailSplit_daemonInbox IS OP p_fldrSrc - for daemon, split inbox into [good, badd] email folders, then process "good" # ??Jan2020 initial - adapted from emailSplit_folder # 27Jan2020 corrections and adaptations to run on Lenovo desktop write 'loading emailSplit_daemonInbox' ; #IF flag_break = l THEN Break ; ENDIF ; # For testing setup : # loaddefs '/home/bill/PROJECTS/Qnial/setup.ndf' # loaddefs link d_QNial_mine 'email - ARED daemon program.ndf' # emailSplit_daemonInbox - must have defined p_inbox email_daemonInbox IS OP p_inbox { LOCAL finn i keyStr last_2lines last_line secondLast_line ; NONLOCAL keyStrsALL last_from_processed p_log p_fldrTwix p_fldrTmp p_last_FROM_processed ; host link 'echo >>"' p_log '" "emailSplit_inbox start : ' timestamp_DDMMMYYYY_HMS '"' ; % depending on options, remove [massEmail, images], mime-to-text, ; preprocess_folder p_inbox p_fldrTwix p_fldrTmp ; % ; % find the first new email ; %last_from_processed is file_base, initialized in daemon_run, and is saved in p_last_FROM_processed ; last_from_processed := host_result link 'cat "' p_last_FROM_processed '" ' ; finn := open p_fldrTmp "r ; i := 0 ; IF (~= '!#$]' last_from_processed) THEN WHILE (NOT OR (~= ??eof (last_line := readfile finn)) (= last_from_processed last_line) ) DO secondLast_line := last_line ; ENDWHILE ; ENDIF ; write link 'last_line= ' last_line ; % ; % process the target email folder ; last_2lines := '999' last_line ; i := 0 ; WHILE (~= ??eof last_line) DO last_2lines := emailRead_one finn last_2lines ; last_line := last last_2lines ; %write last_line ; keyStr := execute email_filter_phrase ; IF (NOT OR (= ??eof last_line) (= keyStr (link daemon 'leftover')) ) THEN daemonEml_to_anonymous ; IF (= ' ENDIF ; i := i + 1 ; IF (i > 10000) THEN last_2lines := ' ' ??eof ; ENDIF ; ENDWHILE ; close finn ; } #*********************************************** #] daemon_run IS - continuous, real-time control loop for ARED daemon # 27Jan2020 initial - still have to handle folder index updates! how do I do that ? no "compact folders" command? # After moving p_inboxes to p_processed, BEFORE launching run_daemon, hopefully p_inboxSize_olds are reset !! write 'loading emailSplit_daemonInbox' ; #IF flag_break = l THEN Break ; ENDIF ; # loaddefs '/home/bill/PROJECTS/Qnial/setup.ndf' # loaddefs link d_QNial_mine 'email - ARED daemon program.ndf' # daemon_run daemon_run IS { LOCAL cycle daemon daemons ; NONLOCAL p_inboxSize_old p_last_FROM_processed p_inbox sleep_time ; % ; daemons := "WCCI2020_contacts "Hussar_contacts ; % reset lastFroms if p_inboxes have been transferred to p_processed ; FOR daemon WITH daemons DO execute daemon ; IF (3 < (file_size p_inbox)) THEN host link 'echo "!#$]" >"' p_last_FROM_processed '" ' ; ENDIF ; ENDFOR ; % ; % loop forever - Ctrl-C to end run ; cycle := l ; WHILE cycle DO write link 'processing : ' first daemons ; execute first daemons ; IF (3 < (- (file_size p_inbox) (tonumber first pName_read_list p_inboxSize_old) ) THEN email_daemonInbox p_inbox ; ELSE write link 'daemon is sleeping : ' timestamp_YYMMDD_HMS ; sleep sleep_time ; % check after sleep_time (seconds) ; ENDIF ; daemons := append [rest, first] daemons ; %cycle := o ; % testing purposes, set = o to run once only ; ENDWHILE ; } #******************************** loaddefs_ended f_emailDaemon ; # enddoc