Add email status to backend
[blerg.git] / aux / cgi / email.cgi
index 0d128b9..62c717d 100755 (executable)
@@ -4,6 +4,7 @@ use Digest::SHA qw/hmac_sha256_base64/;
 use Blerg::Database;
 use URI::Escape;
 use Mail::Message;
+use JSON;
 use strict;
 use v5.10;
 
@@ -141,6 +142,24 @@ EMAIL
 
             say '{"status": "success"}';
         }
+        when ('status') {
+            my $username = validate_authentication($q);
+            if (!defined $username) {
+                print_403;
+                next REQUEST;
+            }
+
+            my $email = undef;
+            my $email_conf_path = Blerg::Database::configuration->{data_path} . "/$username/email";
+            if (-f $email_conf_path) {
+                open CONF, $email_conf_path;
+                $email = <CONF>;
+                close CONF;
+            }
+
+            say header(-type => 'application/json'),
+                JSON->new->utf8->encode({email => $email});
+        }
         when ('cancel') {
             my $username = validate_authentication($q);
             if (!defined $username) {