From a3c02b057d01c52aac43b99dc49f4f5c30ffdf29 Mon Sep 17 00:00:00 2001 From: "Marcel Kapfer (mmk2410)" Date: Sun, 20 Nov 2016 08:47:12 +0100 Subject: [PATCH 01/16] Mails send separatly. Input text used. Res T123,T124 --- .gitignore | 1 + README.md | 10 ++++++ filespread.ini | 3 ++ index.html | 1 + res/dart/.gitignore | 23 ++++++++++++++ res/dart/main.dart | 34 ++++++++++++++++++++ res/js/main.coffee | 18 +++++++++-- res/php/sendmail.php | 76 ++++++++++++++++++++++++-------------------- 8 files changed, 129 insertions(+), 37 deletions(-) create mode 100644 res/dart/.gitignore create mode 100644 res/dart/main.dart diff --git a/.gitignore b/.gitignore index 9021ead..827b588 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ assets/ templates/ lists/ vendor/ +*~ diff --git a/README.md b/README.md index 5359431..3a28b38 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,16 @@ gulp sass gulp coffee ``` +Make sure you have dart installed on your system and run + +``` +cd res/dart/ +``` + +``` +dart2js -m -o main.js main.dart +``` + Create the folders `templates`, `assets` and `lists` and make sure that the server can write in these folders. Finally remove the example files. diff --git a/filespread.ini b/filespread.ini index 8f74fab..f1cac2c 100644 --- a/filespread.ini +++ b/filespread.ini @@ -10,3 +10,6 @@ timezone = "UTC" email = "example@example.com" ; name which is given as a sender name name = "John" +; reply address +; if not set, the values above will be used +reply = "" \ No newline at end of file diff --git a/index.html b/index.html index 3150783..fa3e474 100755 --- a/index.html +++ b/index.html @@ -171,5 +171,6 @@ + diff --git a/res/dart/.gitignore b/res/dart/.gitignore new file mode 100644 index 0000000..2205f7b --- /dev/null +++ b/res/dart/.gitignore @@ -0,0 +1,23 @@ +# Files and directories created by pub +.packages +.pub/ +build/ +packages +# Remove the following pattern if you wish to check in your lock file +pubspec.lock + +# Files created by dart2js +*.dart.js +*.part.js +*.js.deps +*.js.map +*.info.json + +# Directory created by dartdoc +doc/api/ + +# JetBrains IDEs +.idea/ +*.iml +*.ipr +*.iws diff --git a/res/dart/main.dart b/res/dart/main.dart new file mode 100644 index 0000000..6579e18 --- /dev/null +++ b/res/dart/main.dart @@ -0,0 +1,34 @@ +// Copyright (c) 2016, Marcel Kapfer (mmk2410). +// MIT License + +import 'dart:convert'; +import 'dart:html'; + +void main() { + // send mail listener + querySelector("#send").onClick.listen(sendMail); +} + +void sendMail(MouseEvent event) { + InputElement title = querySelector("#mailtitle"); + InputElement text = querySelector("#mailtext"); + InputElement filename = querySelector("#filename"); + InputElement addresslist = querySelector("#address_list"); + + Map data = { + "title": title.value, + "body": text.value, + "filename": filename.value, + "list": addresslist.value + }; + + String url = "/res/php/sendmail.php?data=${JSON.encode(data)}"; + + HttpRequest.getString(url).then((response) { + if (response == "0") { + window.alert("Mails successfully sent."); + } else { + window.alert("Failed to send mail."); + } + }); +} diff --git a/res/js/main.coffee b/res/js/main.coffee index 46d009f..40c80d1 100755 --- a/res/js/main.coffee +++ b/res/js/main.coffee @@ -3,8 +3,21 @@ # MIT License main = -> - + ### $("#send").click -> + url = "/res/php/sendmail.php" + data = new FormData + data.append "json", JSON.stringify + a: 1 + b: "test" + request = new Request url, + method: 'POST' + body: data + fetch request + .then (response) -> + console.log response + ### + ### url = "./res/php/sendmail.php?list=" + $("#address_list").val() + "&template=" + $("#templates_list").val() $.get url, (data) -> @@ -12,7 +25,8 @@ main = -> alert "Mail sent!" else alert "Sending mail failed!" - + ### + updateAddressLists() updateTemplateLists() diff --git a/res/php/sendmail.php b/res/php/sendmail.php index 7f0496f..4720281 100755 --- a/res/php/sendmail.php +++ b/res/php/sendmail.php @@ -8,46 +8,52 @@ date_default_timezone_set($ini["timezone"]); require '../../vendor/autoload.php'; -$list = "../../lists/" . $_GET["list"]; -$template = "../../templates/" . $_GET["template"]; +function main($ini) { -$addresses = file($list); -$content = file($template); + $data = json_decode($_GET["data"], true); -$email = new PHPMailer; + $list = "../../lists/" . $data["list"]; + $addresses = file($list); -$email->setFrom($ini["email"], $ini["name"]); -$email->Subject = parseSubject($content); -$email->Body = parseText($content); + $content = $data["body"]; -foreach ($addresses as $address) { - $email->AddAddress($address); -} + $title = $data["title"]; -$file_to_attach = '../../assets/file.bin'; -$filename = parseFilename($content); + $filename = $data["filename"]; -$email->AddAttachment($file_to_attach, $filename); - -if (!$email->Send()) { - echo "-1"; - echo $email->ErrorInfo; -} else { - echo "0"; -} - -function parseSubject($content) { - return substr($content[0], 7); -} - -function parseFilename($content) { - return substr($content[1], 10); -} - -function parseText($content) { - $text = substr($content[2], 6); - for ($i = 3; $i < count($content); $i++) { - $text = $text . $content[$i]; + foreach ($addresses as $address) { + if (sendMail($title, $content, $filename, $address, $ini) != 0) { + print "-1"; + exit; + } } - return $text; + + print "0"; + } + +function sendMail($title, $content, $filename, $address, $ini) { + + $mail = new PHPMailer; + + $mail->setFrom($ini["email"], $ini["name"]); + $mail->Subject = $title; + $mail->Body = $content; + + $mail->addAddress($address); + + if (isset($ini["reply"])) { + $mail->addReplyTo($ini["reply"]); + } + + $mail->AddAttachment("../../assets/file.bin", $filename); + + if (!$mail->Send()) { + return -1; + } else { + return 0; + } + +} + +main($ini); From ebe2b80e87231523e15a6d398a50f93907014b94 Mon Sep 17 00:00:00 2001 From: "Marcel Kapfer (mmk2410)" Date: Sun, 20 Nov 2016 09:06:13 +0100 Subject: [PATCH 02/16] Removed obsolete code --- res/js/main.coffee | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/res/js/main.coffee b/res/js/main.coffee index 40c80d1..4b156aa 100755 --- a/res/js/main.coffee +++ b/res/js/main.coffee @@ -3,30 +3,6 @@ # MIT License main = -> - ### - $("#send").click -> - url = "/res/php/sendmail.php" - data = new FormData - data.append "json", JSON.stringify - a: 1 - b: "test" - request = new Request url, - method: 'POST' - body: data - fetch request - .then (response) -> - console.log response - ### - ### - url = "./res/php/sendmail.php?list=" + $("#address_list").val() + - "&template=" + $("#templates_list").val() - $.get url, (data) -> - if data is "0" - alert "Mail sent!" - else - alert "Sending mail failed!" - ### - updateAddressLists() updateTemplateLists() From b5303781d6e226bd591059346ff286b5f8a3ea81 Mon Sep 17 00:00:00 2001 From: "Marcel Kapfer (mmk2410)" Date: Mon, 21 Nov 2016 18:09:05 +0100 Subject: [PATCH 03/16] Updated readme --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a28b38..c615a06 100644 --- a/README.md +++ b/README.md @@ -44,4 +44,9 @@ Filespread is licensed under the MIT license. # Contributing -Please refer to the [Contributing Guidlines](https://mmk2410.org/contribute/) +1. Fork it +2. Create a feature branch with a meaningful name (`git checkout -b my-new-feature`) +3. Add yourself to the CONTRIBUTORS file +4. Commit your changes (`git commit -am 'Add some feature'`) +5. Push to your branch (`git push origin my-new-feature`) +6. Create a new pull request From c7d14040b333e056f586c847696bec4d0dffdaef Mon Sep 17 00:00:00 2001 From: "Marcel Kapfer (mmk2410)" Date: Thu, 24 Nov 2016 11:13:12 +0100 Subject: [PATCH 04/16] Fix: Send mail not working in subdirectory Res: T126 --- res/dart/main.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/dart/main.dart b/res/dart/main.dart index 6579e18..91a437b 100644 --- a/res/dart/main.dart +++ b/res/dart/main.dart @@ -22,7 +22,7 @@ void sendMail(MouseEvent event) { "list": addresslist.value }; - String url = "/res/php/sendmail.php?data=${JSON.encode(data)}"; + String url = "res/php/sendmail.php?data=${JSON.encode(data)}"; HttpRequest.getString(url).then((response) { if (response == "0") { From d51fd4e1f4f5667e3389a32533372ee9c0d4678d Mon Sep 17 00:00:00 2001 From: "Marcel Kapfer (mmk2410)" Date: Thu, 24 Nov 2016 11:22:08 +0100 Subject: [PATCH 05/16] Maximal height for address list. Res: T125 --- res/css/main.sass | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/res/css/main.sass b/res/css/main.sass index 7b558c8..b56bd8a 100755 --- a/res/css/main.sass +++ b/res/css/main.sass @@ -180,6 +180,11 @@ input.button .remove_list display: none +#addresses + max-height: 200px + overflow-x: hidden + overflow-y: auto + /* FORM */ form margin-top: 20px From bc9f84a64cafb065fc11e280f3eaa43ad720f39c Mon Sep 17 00:00:00 2001 From: "Marcel Kapfer (mmk2410)" Date: Thu, 8 Dec 2016 11:02:42 +0100 Subject: [PATCH 06/16] Added config file to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 827b588..cdb3104 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ templates/ lists/ vendor/ *~ +filespread.ini From cef1650686d53c7274b48b1bbe9632f631ff3c6f Mon Sep 17 00:00:00 2001 From: Marcel Kapfer Date: Thu, 20 Apr 2017 13:32:09 +0200 Subject: [PATCH 07/16] Send Mail without a file attachment --- index.html | 1 + res/css/main.sass | 6 ++++++ res/dart/main.dart | 7 +++++-- res/php/sendmail.php | 10 +++++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index fa3e474..78ac29d 100755 --- a/index.html +++ b/index.html @@ -68,6 +68,7 @@

Change the text of the email if you want.

Title:

Text:

+

Send without file

Filename:

diff --git a/res/css/main.sass b/res/css/main.sass index b56bd8a..12df386 100755 --- a/res/css/main.sass +++ b/res/css/main.sass @@ -163,6 +163,12 @@ input.button .itextarea:focus @extend .itextfield +.icheckbox + margin: 0 + padding: 0 + margin-right: 10px + vertical-align: sub + /* FILESPREAD */ .edit_template diff --git a/res/dart/main.dart b/res/dart/main.dart index 91a437b..77c345f 100644 --- a/res/dart/main.dart +++ b/res/dart/main.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2016, Marcel Kapfer (mmk2410). +// Copyright (c) 2016 - 2017, Marcel Kapfer (mmk2410). // MIT License import 'dart:convert'; @@ -14,12 +14,14 @@ void sendMail(MouseEvent event) { InputElement text = querySelector("#mailtext"); InputElement filename = querySelector("#filename"); InputElement addresslist = querySelector("#address_list"); + CheckboxInputElement nofile = querySelector("#nofile"); Map data = { "title": title.value, "body": text.value, "filename": filename.value, - "list": addresslist.value + "list": addresslist.value, + "nofile": nofile.checked }; String url = "res/php/sendmail.php?data=${JSON.encode(data)}"; @@ -31,4 +33,5 @@ void sendMail(MouseEvent event) { window.alert("Failed to send mail."); } }); + } diff --git a/res/php/sendmail.php b/res/php/sendmail.php index 4720281..af9782a 100755 --- a/res/php/sendmail.php +++ b/res/php/sendmail.php @@ -21,6 +21,12 @@ function main($ini) { $filename = $data["filename"]; + $nofile = $data["nofile"]; + + if ($nofile) { + $filename = ""; + } + foreach ($addresses as $address) { if (sendMail($title, $content, $filename, $address, $ini) != 0) { print "-1"; @@ -46,7 +52,9 @@ function sendMail($title, $content, $filename, $address, $ini) { $mail->addReplyTo($ini["reply"]); } - $mail->AddAttachment("../../assets/file.bin", $filename); + if (!empty($filename)) { + $mail->AddAttachment("../../assets/file.bin", $filename); + } if (!$mail->Send()) { return -1; From 53421bcae0c523a00197eac57159ef6f58f13438 Mon Sep 17 00:00:00 2001 From: Marcel Kapfer Date: Tue, 23 May 2017 16:47:16 +0200 Subject: [PATCH 08/16] documented the sendmail.php script. --- res/php/sendmail.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/res/php/sendmail.php b/res/php/sendmail.php index af9782a..33abdce 100755 --- a/res/php/sendmail.php +++ b/res/php/sendmail.php @@ -2,12 +2,22 @@ # COPYRIGHT (c) 2016 Marcel Kapfer (mmk2410) # MIT License +/** + * configuration map + */ $ini = parse_ini_file("../../filespread.ini"); date_default_timezone_set($ini["timezone"]); require '../../vendor/autoload.php'; +/** + * main function that is executed at the beginning. + * + * @author Marcel Kapfer + * + * @param $ini an configuration map. + */ function main($ini) { $data = json_decode($_GET["data"], true); @@ -38,6 +48,16 @@ function main($ini) { } +/** + * function for sending the mail. + * + * @author Marcel Kapfer + * + * @param $title the subject of the mail. + * @param $content the text of the mail. + * @param $address the receiver of the mail. + * @param $ini an configuration map. + */ function sendMail($title, $content, $filename, $address, $ini) { $mail = new PHPMailer; From 31ea5325234469d4712ebdc0f9179e6f9b1f92ba Mon Sep 17 00:00:00 2001 From: Marcel Kapfer Date: Tue, 23 May 2017 16:47:37 +0200 Subject: [PATCH 09/16] set charset to utf-8 in sendmail.php script. --- res/php/sendmail.php | 1 + 1 file changed, 1 insertion(+) diff --git a/res/php/sendmail.php b/res/php/sendmail.php index 33abdce..8c5e506 100755 --- a/res/php/sendmail.php +++ b/res/php/sendmail.php @@ -61,6 +61,7 @@ function main($ini) { function sendMail($title, $content, $filename, $address, $ini) { $mail = new PHPMailer; + $mail->CharSet = 'UTF-8'; $mail->setFrom($ini["email"], $ini["name"]); $mail->Subject = $title; From 530e3c8ce28a9c37fbfddfb270ab63ec86938e0b Mon Sep 17 00:00:00 2001 From: Marcel Kapfer Date: Thu, 15 Jun 2017 23:58:59 +0200 Subject: [PATCH 10/16] Added dart task to gulpfile --- gulpfile.coffee | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gulpfile.coffee b/gulpfile.coffee index de480a1..3ae8d4d 100755 --- a/gulpfile.coffee +++ b/gulpfile.coffee @@ -4,6 +4,7 @@ gulp = require 'gulp' coffee = require 'gulp-coffee' sass = require 'gulp-sass' +dart = require 'gulp-dart' gulp.task 'coffee', -> gulp.src './res/js/*.coffee' @@ -15,6 +16,15 @@ gulp.task 'sass', -> .pipe sass() .pipe gulp.dest './res/css/' +gulp.task 'dart', -> + gulp.src './res/dart/*.dart' + .pipe dart { + "dest": "./res/dart/", + "minify": "true", + } + .pipe gulp.dest './res/dart/' + gulp.task 'default', -> gulp.watch './res/js/*.coffee', ['coffee'] gulp.watch './res/css/*.sass', ['sass'] + gulp.watch './res/dart/*.dart', ['dart'] From fb64ad895c33d7b7cb4e456df69ff1d6c006da94 Mon Sep 17 00:00:00 2001 From: Marcel Kapfer Date: Thu, 15 Jun 2017 23:59:40 +0200 Subject: [PATCH 11/16] Extended gitignore with *.sum --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index cdb3104..4ecebc5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ lists/ vendor/ *~ filespread.ini +*.sum \ No newline at end of file From 1a657aac2d020362a5aecdbd3b32a1556fccc565 Mon Sep 17 00:00:00 2001 From: Marcel Kapfer Date: Fri, 16 Jun 2017 00:01:00 +0200 Subject: [PATCH 12/16] Fixed dart script include Fixed file extension (changed because of the gulp task) and made it load async. --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 78ac29d..39cfabd 100755 --- a/index.html +++ b/index.html @@ -172,6 +172,6 @@ - + From 9f605bb12ff41980e6e16cbc5ae18217654c6b67 Mon Sep 17 00:00:00 2001 From: Marcel Kapfer Date: Fri, 16 Jun 2017 00:03:43 +0200 Subject: [PATCH 13/16] Added gulp-dart as a requirement to package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 0dd2fac..d92b6ed 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "devDependencies": { "gulp": "^3.9.1", "gulp-coffee": "^2.3.1", + "gulp-dart": "^0.2.4", "gulp-sass": "^2.1.0", "node-sass": "^3.4.2" }, From 56e607c04a0d642fbce8f2a3cd5705f8e07277a9 Mon Sep 17 00:00:00 2001 From: Marcel Kapfer Date: Fri, 16 Jun 2017 00:04:50 +0200 Subject: [PATCH 14/16] Implemented new saveAddresses method in Dart Fixes the bug, that long list can't be sent via get methods. --- res/dart/main.dart | 50 ++++++++++++++++++++++++++++++++++++++++++-- res/php/savelist.php | 4 ++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/res/dart/main.dart b/res/dart/main.dart index 77c345f..0881b29 100644 --- a/res/dart/main.dart +++ b/res/dart/main.dart @@ -1,14 +1,20 @@ // Copyright (c) 2016 - 2017, Marcel Kapfer (mmk2410). // MIT License +/// frontend code for filespread, a simple file over email spreading web app. import 'dart:convert'; import 'dart:html'; +/// main method with click listners. void main() { // send mail listener querySelector("#send").onClick.listen(sendMail); + + // save address list listner + querySelector("#save-addresses").onClick.listen(saveAddresses); } +/// function for calling the backend to send mails. void sendMail(MouseEvent event) { InputElement title = querySelector("#mailtitle"); InputElement text = querySelector("#mailtext"); @@ -26,12 +32,52 @@ void sendMail(MouseEvent event) { String url = "res/php/sendmail.php?data=${JSON.encode(data)}"; - HttpRequest.getString(url).then((response) { + HttpRequest.getString(url).then((String response) { if (response == "0") { window.alert("Mails successfully sent."); } else { window.alert("Failed to send mail."); } }); - +} + +/// function to update the addresses list in the backend. +void saveAddresses(MouseEvent event) { + TextAreaElement addresses = querySelector("#edit-addresses"); + SelectElement list = querySelector("#edit-address-list"); + + List addressesList = new List(); + + addresses.value.split("\n").forEach((String address) { + if (address.isNotEmpty) addressesList.add(address); + }); + + Map data = {"list": list.value, "addresses": addressesList}; + + String url = "res/php/savelist.php"; + + HttpRequest.postFormData(url, {"data": JSON.encode(data)}).then((HttpRequest response) { + if (response.responseText == "0") { + window.alert("Addresses sucessfully saved."); + updateAddresses(addressesList, list.value); + } else { + window.alert("Failed to save adresses."); + } + }); +} + +/// Updated the frontend after an address change. +void updateAddresses(List addresses, String list) { + SelectElement currentList = querySelector("#address_list"); + + if (currentList.value == list) { + DivElement addressesContainer = querySelector("#addresses"); + addressesContainer.children .removeWhere((Element child) => addressesContainer.children.contains(child)); + + addresses.forEach((String address) { + ParagraphElement addressElement = new ParagraphElement(); + addressElement.text = address; + addressesContainer.children.add(addressElement); + }); + } } diff --git a/res/php/savelist.php b/res/php/savelist.php index a2f9b56..8f223e5 100644 --- a/res/php/savelist.php +++ b/res/php/savelist.php @@ -1,8 +1,8 @@ Date: Fri, 16 Jun 2017 00:05:05 +0200 Subject: [PATCH 15/16] Removed obsolete CoffeeScript code --- res/js/main.coffee | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/res/js/main.coffee b/res/js/main.coffee index 4b156aa..6972938 100755 --- a/res/js/main.coffee +++ b/res/js/main.coffee @@ -105,20 +105,6 @@ main = -> $("#edit-addresses").val(text) $(".edit_address").fadeIn() - $("#save-addresses").click -> - data = - list: $("#edit-address-list").val() - addresses: $("#edit-addresses").val().split '\n' - if data.addresses[data.addresses.length - 1] is "" - data.addresses.pop() - $.get "./res/php/savelist.php", {"data": data}, (data) -> - if data == "0" - alert "List sucessfully changed!" - if data.list is $("#address_list") - updateAddresss data.list - else - alert "Error while saving the edit." - $("#create-list").click -> filename = $("#create-list-name").val() if filename.substring((filename.length - 4)) isnt ".txt" From 20ab0b03f974d9535628ce4412839ab80b9e42a3 Mon Sep 17 00:00:00 2001 From: Marcel Kapfer Date: Fri, 16 Jun 2017 00:14:16 +0200 Subject: [PATCH 16/16] Changed README concerning Dart. --- README.md | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c615a06..6a2dede 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ npm install composer install ``` -Make sure you have gulp installed on your system and run +Make sure you have gulp and the Dart SDK installed on your system and run ``` gulp sass @@ -24,14 +24,8 @@ gulp sass gulp coffee ``` -Make sure you have dart installed on your system and run - ``` -cd res/dart/ -``` - -``` -dart2js -m -o main.js main.dart +gulp dart ``` Create the folders `templates`, `assets` and `lists` and make sure that the server can write in these folders.