#!/bin/sed -unrf # read config into hold buffer h; # use domain as to s#^\S+@(\S+)\s.+$##; p;n; :wait-for-plain; /^PLAIN<\/mechanism$/bauth-with-plain; n; bwait-for-plain; :auth-with-plain; # load config g; s#^\S+\s+(\S+)$#\1#; p;n; bwait-for-sasl-result; :wait-for-sasl-result; /^#; p;n; bwait-for-bind; :sasl-failure; s#^.+$##; q1; :wait-for-bind; /^#;p;n; bwait-for-bind-result; :wait-for-bind-result; /#;p;q1; :send-presence; s#^.+$##;p;n; bmain-loop; :main-loop; /#; # store result in hold space h; bmessage-search-body-loop; :message-search-body-loop; # drop message if end-of-message before body \#\1#; # append result to hold space H; # load full hold space and append and send g; s#^(.+)$#\1#; p;n; bmain-loop; :handle-iq; # prepare header; store it in hold space first h; # extract new to address s#^.*from=(['"][^'"]+?['"]).*$#to=\1\n#; # add copy of header and extract new from address G; s#^(.+)\n.+to=(['"][^'"]+?['"]).*$#\1 from=\2#; # add copy of header and extract id G; s#^(.+)\n.+id=(['"][^'"]+?['"]).*$#\1 id=\2#; # compose header s#^(.+)$##; # store result in hold space and fetch original header for further processing x; /type='get'/bsend-error; /type='set'/bsend-error; bmain-loop; :send-error; # load composed header from hold space g; s#^$#Feature not implemented by sedbot.#; p;n; bskip-iq; :skip-iq; # skip remainder of IQ payload until done /<\/iq/bmain-loop; n; bskip-iq;