Writing moderator expert system in OPS5 - expert-system

I'm trying to build a site with automated moderation using the rule based language OPS5.
I can't seem to get the rules right as my messages are being auto banned.
(literalize moderator
name
competencelevel)
(literalize message
body
ontopic
banned)
(startup
(make moderator ^name john ^competencelevel low)
(make moderator ^name joe ^competencelevel low)
(make moderator ^name bob ^competencelevel low)
(make message ^body body1 ^ontopic yes ^banned no)
(make message ^body body2 ^ontopic yes ^banned no)
(make message ^body body3 ^ontopic yes ^banned no)
(make message ^body body3 ^ontopic no ^banned no)
)
(p rule1
(message ^body <body> ^ontopic <ontopic> ^banned <banned>)
(moderator ^name <name> ^competencelevel {<competencelevel> = low})
-->
(make message ^body <body> ^ontopic <ontopic> ^banned yes)
)
(p rule2
(message ^body <body> ^ontopic <ontopic> ^banned {<banned> = yes})
-->
(write (crlf) |The message has been banned
(crlf)
)

Related

Sent html email using gmail API, it appears in "chinese" on apple mail client

I am sending emails using the Gmail NodeJS API using these code snippet (leaving auth out of it)
const headers: any = {
'To': event.to,
'Subject': event.subject,
"Content-Type": "text/html; charset='UTF-8'",
"Content-Transfer-Encoding": "base64"
}
let email = ''
for (let header in headers) {
email += header += ": " + headers[header] + "\r\n";
}
email += "\r\n" + event.body;
const theMessage = {
'userId': "me",
'resource': {
'raw': _btoa(unescape(encodeURIComponent(email))).replace(/\+/g, '-').replace(/\//g, '_')
}
}
const auth = new google.auth.OAuth2(
webAppClientId, this.clientSecret, "https://docs-n-data......");
const gmail = google.gmail({version: 'v1', auth})
gmail.users.messages.send(theMessage)
The email renders correctly on most email clients, except the ios email client on iphone. It looks like "chinese" in that client. Please see the attached image, following the suggestion by #DalmTo:
Some articles on the web hint that this might be due to the email being interpreted as UTF-16 instead of UTF-8, but none of them explain what to do.
I am trying to state that the encoding is UTF-8 in the above code, so am not sure whats wrong. Please help, thanks!
Update Maybe the content of the email body is important. The content comes from this template:
const emailBody = `<html>
<body>
<p>Hi {{Customer.First name}},</p>
<p>Your booking is confirmed for {{Date}} at {{Time}} and we have charged you the
amount of £{{Paid}}</p>
<p>Your booking reference is {{Booking number}}.</p>
<p>Use this link to cancel your booking, should you wish to.</p>
<p>Use this link to amend your booking, should you wish to.</p>
</body>
</html>`
Update 2 I changed the template for the email to:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<p>Hi {{Customer.First name}},</p>
<p>Your booking with The Smart Wash Ltd is confirmed for {{Date}} at {{Time}} and we have charged you the
amount of £{{Paid}}</p>
<p>Your booking reference is {{Booking number}}.</p>
</body>
</html>
And now I get this rendering on iphone mail client. On the ipad mail client and gmail, it renders correctly:
When I view the same email in gmail, and "Show original", I see this:
Not sure who or what is putting the text/plain version in there, but including this detail in case it helps.
I setted "Content-Transfer-Encoding": "8bit" and it worked for me!

change font size for phpmailer subject

The following function works but I am unable to control the font-size of the "Subject". Is there a way to change the font size of the "Subject". I've tried:
$mail->Subject = "<span style='font-size:3vw'>" .$mailInputs['subject'] ."<\span>";
but that didn't work.
function mailerExpressBlueHost(array $mailInputs){
require_once '../includes/phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsMail();
$mail->SetFrom('example#xyz.com');
$mail->IsHTML(true);
$mail->addAddress('abc#example.com');
$mail->AddEmbeddedImage("../public/img/swb.jpg", "swb-image");
$body = '<!DOCTYPE html>
<html><header>
</header>
<body lang=EN-US>
<div style="text-align:center">
<img src="cid:swb-image">' . $mailInputs['body'] ;
$mail->isHTML(true);
$mail->Subject = $mailInputs['subject'] ;
$mail->Body = $body;
if(!$mail->send()) {
return 'Message could not be sent.' . 'Mailer Error: ' . $mail->ErrorInfo;
} else {
return 'Message has been sent';
}
$mail->ClearAddresses();
}
No, you can't do this. The Subject line does not support HTML formatting; it's plain text only - not least because the definition of the Subject email header predates HTML by at least 10 years.
On the upside, you can use unicode, which allows you quite a lot of tricks, but it's highly dependent on the OS and application it's viewed in.

phpMailer not sending emails with no errors

I'm having this issue regarding sending emails using phpMailer
My code is
public function sendEmailNovoUtilizador($nome, $email){
$mail = new PHPMailer;
$mail->SMTPDebug = 1;
$mail->isSMTP();
$mail->Host = 'xxxxx.xxxxxxx.pt';
$mail->SMTPAuth = true;
$mail->Username = 'xxxxxxx#xxxxxx.edu.pt';
$mail->Password = 'xxxxxxx';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('xxxxxxx#xxxxxx.edu.pt', 'Diretor');
$mail->addAddress($email, 'Novo utilizador');
$mail->IsHTML(true);
$mail->Subject = 'Registo de um novo utilizador';
$mail->CharSet = 'UTF-8';
$mail->Body = "
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
</head>
<body>
<h1>Novo Utilizador</h1>
<p>Seguem os seus dados</p>
<table>
<tbody>
<tr>
<td><strong>Nome:</strong></td>
<td>$nome</td>
</tr>
<tr>
<td><strong>Email:</strong></td>
<td>$email</td>
</tr>
</tbody>
</table>
<p> </p>
<p>Aguarde a validação por parte do Diretor</p>
<p> </p>
<p>Equipa ESMAIOR.</p>
<p> </p>
<p>Obrigado</p>
</body>
</html>";
$mail->addAttachment('../img/logo_pdf.jpg');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
Error i get when i log into my server
Delivery Event Details
Event: failure
User: ebspma
Domain: xxxx.edu.pt
Sender: xxxxxx#xxxx.edu.pt
Sent Time: Sep 2, 2016 10:56:22 PM
Sender Host: xxxxxx.edu.pt
Sender IP: 109.71.40.19
Authentication: dovecot_login
Spam Score: 0
Recipient: xxxxxxx#gmail.com
Delivery User:
Delivery
Domain:
Delivered To:
Router: smarthost_cleanmx_regular
Transport: remote_smtp_cleanmx_smart_regular
Out Time: Sep 2, 2016 10:56:22 PM
ID: 1bfwS2­002VOU­Q4
Delivery Host: smtp.cleanmx.pt
Delivery IP: 130.185.80.200
Size: 6.52 KB
Result:
DHE­RSA­AES256­SHA:256 CV=yes DN="/OU=Domain Control
Validated/CN=*.cleanmx.pt": SMTP error from remote mail server after MAIL FROM:
<xxxxxx#xxxxx.edu.pt> SIZE=7818: 550­ Verification failed for
<xxxxxx#xxxx.edu.pt>\n550­Previous (
What's wrong, it seems it connect but can't delivery? This is what i get from my server log in email delivery

Can I use seperate app.post requests for different divs on the same page?

I have a page with a sidebar that can change its function. Each different sidebar layout is a div. Two of the sidebars allow for text input. Right now I have one app.get statement that calls a handler that deals with all the sidebar layouts, but this solution is very messy. How would I go about splitting the different sidebars to work with different handler functions?
For example, I have this statement in app.js:
app.post('/', home.sidebarHandler);
sidebarHandler currently handles both logging in and registering as a new user, but I would like this to be done by two separate functions.
Here's part of my jade code, this is one of the divs:
form#sbCreateBox(method='post')
input.sbText(type='text', name= 'usernameReg', placeholder='Username', required)
input.sbText(type='text', name= 'acctHolderName', placeholder='Name')
input.sbText(type='email', name= 'useremail', placeholder='Email Address', required)
input.sbText(type='password', name= 'passwordReg', autocomplete='off', placeholder='Password', required)
input.sbText(type='password', name= 'passConfirm', autocomplete='off', placeholder='Confirm Password', required)
input#sbCreateButton(type='submit', value='Create Account')
How might I setup the routes to have separate app.post statements?
You could define two routes in your server side code:
app.post('/register', home.registerUser);
app.post('/login', home.loginUser);
And update your HTML to post to the correct URL (/register or /login) depending on the user's action.
EDIT
You can create two forms. One will post to /register and the other to /login (notice the action attribute on the form element):
Register Form
form#sbCreateBox(method='post' action='/register')
input.sbText(type='text', name= 'usernameReg', placeholder='Username', required)
input.sbText(type='text', name= 'acctHolderName', placeholder='Name')
input.sbText(type='email', name= 'useremail', placeholder='Email Address', required)
input.sbText(type='password', name= 'passwordReg', autocomplete='off', placeholder='Password', required)
input.sbText(type='password', name= 'passConfirm', autocomplete='off', placeholder='Confirm Password', required)
input#sbCreateButton(type='submit', value='Create Account')
Login Form
form#sbCreateBox(method='post' action='/login')
input.sbText(type='text', name= 'usernameReg', placeholder='Username', required)
input.sbText(type='password', name= 'passwordReg', autocomplete='off', placeholder='Password', required)
input#sbCreateButton(type='submit', value='Login')

The following lisp program doesn't work as expected

The followwing is my lisp code to complish a simple web server.
; 一些辅助函数
(require :asdf)
(defun loadlib (mod)
(asdf:oos 'asdf:load-op mod))
(defun reload ()
(load "web.lisp"))
; load 需要的库
(loadlib :html-template)
(loadlib :hunchentoot)
; 设置 hunchentoot 编码
(defvar *utf-8* (flex:make-external-format :utf-8 :eol-style :lf))
(setq hunchentoot:*hunchentoot-default-external-format* *utf-8*)
; 设置url handler 转发表
(push (hunchentoot:create-prefix-dispatcher "/hello" 'hello) hunchentoot:*dispatch-table*)
; 页面控制器函数
(defun hello ()
(setf (hunchentoot:content-type*) "text/html; charset=utf-8")
(with-output-to-string (stream)
(html-template:fill-and-print-template
#P"/home/chonglinsun/Learn/cl/lib/web/index.tmpl"
(list :name "Lisp程序员")
:stream stream)))
; 启动服务器
(defun start-web (&optional (port 4444))
(hunchentoot:start (make-instance 'hunchentoot:acceptor :port port)))
(defun restart-web ()
(progn
(reload)
(start-web)))
index.tmpl 的内容如下:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Lisp Web</title>
</head>
<body>
<h1>Lisp web开发实例</h1>
hi, <!-- TMPL_VAR name -->
</body>
</html>
When I start-web, I can not access localhost:4444/hello, but I can not firgure where
the problem is. I searched the Internet, some people said that is my because of the
path. But I do not think there is something related to it in my code. Hope there would be
someone coming tell me why. I used ubuntu 12.10.
You need to use an easy-acceptor instead of an acceptor to use the *dispatch-table* mechanism.

Resources