const fs = require("fs") const { exec } = require("child_process"); const serverPath = require("./serverPath.js") const members = require("/etc/newsletter_members.js") const blogs = require(serverPath+"/blogs/blogs.js") let finalBlogIndex = blogs.length-1 const final_blog = blogs[finalBlogIndex] const lastBlogIndex = require(serverPath+"/node/previousBlog.js") if (finalBlogIndex > lastBlogIndex || process.argv[2] == "--test") { final_blog[1] = final_blog[1].replace(/(?:\r\n|\r|\n)/g, '
') final_blog[1] = final_blog[1].replace(/(?:\t)/g, '     ') final_blog[1] = final_blog[1].replace(/\(/g,'\\(') final_blog[1] = final_blog[1].replace(/\)/g,'\\)') final_blog[1] = final_blog[1].replace(/\&/g,'\\&') final_blog[1] = final_blog[1].replace(/'/g,"\\'") let imageAttachments = final_blog[3] ? `${final_blog[3].map(image => `-a ${serverPath}/images/${image}`).join('')}` : ''; console.log(imageAttachments); //console.log(final_blog[1]) if (process.argv[2] == "--test") { console.log("test") let command = `echo "

----TEST POST----


Date created: ${final_blog[2]}


${final_blog[1]}

Original Post" | mutt -e "set content_type=text/html" -s "DeaDvey's Blog (TEST): ${final_blog[0]}" test@deadvey.com ${imageAttachments}` console.log(`--------------\nFULL COMMAND TO RUN: ${command}\n---------------`) exec(command) } else if (finalBlogIndex > lastBlogIndex) { console.log("full distribution!!!") for (let current_member = 0; current_member < members.length; current_member++) { let command = `echo "

Date created: ${final_blog[2]}


${final_blog[1]}

Original Post
Unsubscribe" | mutt -e "set content_type=text/html" -s "DeaDvey's Blog: ${final_blog[0]}" ${members[current_member]} ${imageAttachments}` exec(command) console.log(`sent to ${members[current_member]}`) } } } finalBlogIndex = blogs.length-1 fs.writeFileSync(serverPath+"/node/previousBlog.js", `let lastBlog=${finalBlogIndex.toString()}; if (typeof module !== 'undefined' && module.exports) { module.exports = lastBlog; }`);