diff --git a/docker/rootfs/nginx.conf b/docker/rootfs/nginx.conf index 6e48591..5c11558 100644 --- a/docker/rootfs/nginx.conf +++ b/docker/rootfs/nginx.conf @@ -4,27 +4,14 @@ server { set $base /var/www/opentrashmail; root /var/www/opentrashmail/web/; - index index.html; + index index.php; client_max_body_size 10M; location / { - try_files $uri $uri/ =404; + try_files $uri $uri/ /index.php; } - location /rss { - index rss.php; - if (!-e $request_filename){ - rewrite ^(.*)$ /rss.php?url=$1 last; - } - } - - location /api { - index api.php; - if (!-e $request_filename){ - rewrite ^(.*)$ /api.php?url=$1 last; - } - } # logging access_log /var/log/nginx/opentrashmail/web.access.log; diff --git a/docker/rootfs/start.sh b/docker/rootfs/start.sh index ca07589..cf96cc3 100644 --- a/docker/rootfs/start.sh +++ b/docker/rootfs/start.sh @@ -28,6 +28,13 @@ else echo "DOMAINS=localhost" >> /var/www/opentrashmail/config.ini fi +if [ "$URL" != "" ]; then + echo "URL=$URL" >> /var/www/opentrashmail/config.ini + echo " [i] URL of GUI is set to: $URL" +else + echo "URL=http://localhost:8080" >> /var/www/opentrashmail/config.ini +fi + if [ "$SHOW_ACCOUNT_LIST" != "" ]; then echo "SHOW_ACCOUNT_LIST=$SHOW_ACCOUNT_LIST" >> /var/www/opentrashmail/config.ini echo " [i] Set show account list to: $SHOW_ACCOUNT_LIST" diff --git a/docs/Dev.md b/docs/Dev.md new file mode 100644 index 0000000..c8f7e5a --- /dev/null +++ b/docs/Dev.md @@ -0,0 +1,19 @@ +# Quick testing + +From the main directory run + +```bash +docker build -f docker/Dockerfile -t opentrashmail . && docker run --rm -it --name trashmail -p 3000:80 -p 2525:25 opentrashmail +``` + +And check if it works on http://localhost:3000 + +## Sending debug emails from the command line + +Using the text file `tools/testmail.txt` and the following line of bash you can send emails to your server and test if it's acceping emails like you want. + +Note that if you change cour config.ini, the mail server needs to be restarted before it takes effect. + +```bash +cat "tools/testmail.txt" | while read L; do sleep "0.2"; echo "$L"; done | "nc" -C -v "localhost" "2525" +``` \ No newline at end of file diff --git a/docs/Docker.md b/docs/Docker.md deleted file mode 100644 index 3159f5e..0000000 --- a/docs/Docker.md +++ /dev/null @@ -1,9 +0,0 @@ -# Quick testing - -From the `docker` directory run - -```bash -docker build -t opentrashmail . && docker run --rm -it --name trashmail -p 3000:80 -p 2525:25 opentrashmail -``` - -And check if it works on http://localhost:3000 \ No newline at end of file diff --git a/python/mailserver.py b/python/mailserver.py old mode 100644 new mode 100755 index deab5ef..6e3d52d --- a/python/mailserver.py +++ b/python/mailserver.py @@ -171,6 +171,8 @@ if __name__ == '__main__': DELETE_OLDER_THAN_DAYS = (Config.get("CLEANUP","DELETE_OLDER_THAN_DAYS").lower() == "true") print "[i] Starting Mailserver on port",port + print "[i] Discard unknown domains:",DISCARD_UNKNOWN + print "[i] Listening for domains:",DOMAINS server = CustomSMTPServer(('0.0.0.0', port), None) # use your public IP here print "[i] Ready to receive Emails" diff --git a/tools/testmail.txt b/tools/testmail.txt new file mode 100644 index 0000000..8fc3398 --- /dev/null +++ b/tools/testmail.txt @@ -0,0 +1,14 @@ +HELO localhost +MAIL FROM: +RCPT TO: +DATA +Subject: Test Message + +Hi there! This is supposed to be an email... + +Have a good day! +-- System + + +. +QUIT diff --git a/web/inc/OpenTrashmailBackend.class.php b/web/inc/OpenTrashmailBackend.class.php index c3f1261..1fcc950 100644 --- a/web/inc/OpenTrashmailBackend.class.php +++ b/web/inc/OpenTrashmailBackend.class.php @@ -57,6 +57,41 @@ class OpenTrashmailBackend{ ]); } + //json api + else if($this->url[0]=='json') + { + header("Content-Type: application/json; charset=UTF8"); + if($this->url[1]=='listaccounts') + { + if($this->settings['SHOW_ACCOUNT_LIST']) + return json_encode(listEmailAdresses()); + else exit(json_encode(['error'=>'403 Forbidden'])); + } + $email = $this->url[1]; + if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) { + http_response_code(404); + exit(json_encode(['error'=>'Email not found'])); + } + $id = $this->url[2]; + if($id) //user wants a specific email ID + { + if(!emailIDExists($email,$id)) + { + http_response_code(404); + exit(json_encode(['error'=>'Email ID not found'])); + } + else if(!ctype_digit($id)) + { + http_response_code(400); + exit(json_encode(['error'=>'Invalid ID'])); + } + else + return json_encode(getEmail($email,$id)); + } + else + return json_encode(getEmailsOfEmail($email,true,true)); + } + else return false; } diff --git a/web/inc/core.php b/web/inc/core.php index 4e6dff4..4958277 100644 --- a/web/inc/core.php +++ b/web/inc/core.php @@ -38,7 +38,7 @@ function emailIDExists($email,$id) return file_exists(getDirForEmail($email).DS.$id.'.json'); } -function getEmailsOfEmail($email) +function getEmailsOfEmail($email,$includebody=false,$includeattachments=false) { $o = []; $settings = loadSettings(); @@ -62,6 +62,15 @@ function getEmailsOfEmail($email) 'md5'=>md5($time.$json['raw']), 'maillen'=>strlen($json['raw']) ); + if($includebody==true) + $o[$time]['body'] = $json['parsed']['body']; + if($includeattachments==true) + { + $o[$time]['attachments'] = $json['parsed']['attachments']; + //add url to attachments + foreach($o[$time]['attachments'] as $k=>$v) + $o[$time]['attachments'][$k] = $settings['URL'].'/api/attachment/'.$email.'/'. $v; + } } } closedir($handle); @@ -76,8 +85,23 @@ function getEmailsOfEmail($email) if (endsWith($entry,'.json')) { $time = substr($entry,0,-5); $json = json_decode(file_get_contents(getDirForEmail($email).DS.$entry),true); - $o[$time] = array('email'=>$email,'id'=>$time,'from'=>$json['parsed']['from'],'subject'=>$json['parsed']['subject'],'md5'=>md5($time.$json['raw']),'maillen'=>strlen($json['raw'])); - } + $o[$time] = array( + 'email'=>$email, + 'id'=>$time, + 'from'=>$json['parsed']['from'], + 'subject'=>$json['parsed']['subject'], + 'md5'=>md5($time.$json['raw']),'maillen'=>strlen($json['raw']) + ); + if($includebody==true) + $o[$time]['body'] = $json['parsed']['body']; + if($includeattachments==true) + { + $o[$time]['attachments'] = $json['parsed']['attachments']; + //add url to attachments + foreach($o[$time]['attachments'] as $k=>$v) + $o[$time]['attachments'][$k] = $settings['URL'].'/api/attachment/'.$email.'/'. $v; + } + } } closedir($handle); } diff --git a/web/index.php b/web/index.php index 9d3659c..33e0eff 100644 --- a/web/index.php +++ b/web/index.php @@ -12,7 +12,7 @@ $backend = new OpenTrashmailBackend($url); if($_SERVER['HTTP_HX_REQUEST']!='true') { if(count($url)==0 || !file_exists(ROOT.DS.implode('/', $url))) - if($url[0]!='api' && $url[0]!='rss') + if($url[0]!='api' && $url[0]!='rss' && $url[0]!='json') exit($backend->renderTemplate('index.html',[ 'url'=>implode('/', $url), 'settings'=>loadSettings(), diff --git a/web/templates/account-list.html.php b/web/templates/account-list.html.php index 646936a..bb08bd4 100644 --- a/web/templates/account-list.html.php +++ b/web/templates/account-list.html.php @@ -1,3 +1,7 @@ +
+ JSON API +
+ @@ -16,7 +20,8 @@ diff --git a/web/templates/email-table.html.php b/web/templates/email-table.html.php index d2360c2..21571cf 100644 --- a/web/templates/email-table.html.php +++ b/web/templates/email-table.html.php @@ -1,10 +1,17 @@ +
+ Copy address to clipboard + RSS Feed + JSON API +
+
- + Show + Delete
@@ -30,13 +37,17 @@
-
-
-
-
+ Open + Delete
- \ No newline at end of file + + \ No newline at end of file diff --git a/web/templates/rss.xml.php b/web/templates/rss.xml.php index 68d7357..276fa0d 100644 --- a/web/templates/rss.xml.php +++ b/web/templates/rss.xml.php @@ -14,6 +14,7 @@ $d): $data = getEmail($email, $id); $time = substr($id, 0, -3); + $att_text = []; if (is_array($data['parsed']['attachments'])) foreach ($data['parsed']['attachments'] as $filename) { $filepath = ROOT . DS . '..' . DS . 'data' . DS . $email . DS . 'attachments' . DS . $filename;