Skip to content

Commit

Permalink
PAAMS 2024 Version
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsonLazarin committed May 18, 2024
1 parent 554f4aa commit 0cfe4ba
Show file tree
Hide file tree
Showing 14 changed files with 422 additions and 173 deletions.
395 changes: 395 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Mailer BDI-agent Architecture
[![](https://jitpack.io/v/chon-group/Mailer.svg)](https://jitpack.io/#chon-group/Mailer)

Multi-Agent Systems (MAS) are groups of autonomous agents that act in the same environment, competing or collaborating to achieve individual or collective goals.
Some main challenges encountered in communicating different MAS are the connectionless protocols used by some IoT middlewares for agent communication and the lack of security in transferring messages over the internet.
The Mailer Agent is a customized BDI-based agent architecture that extends the standard [Jason](https://github.com/jason-lang/jason) agent by adding the ability to exchange messages by a connection-oriented communication architecture using secure channels provided by protocols IMAP and SMTP.
Besides, this work contributes to the advancement of MAS by addressing the integration of email protocols to enable secure and simplified human-agent interaction.

![](https://raw.githubusercontent.com/wiki/chon-group/Mailer/.imgs/mailerAgentArch.png)


#### See the [Mailer Wiki](https://github.com/chon-group/Mailer/wiki/) to learn how to use this agent architecture in your Multi-agent System.


## Copyright
<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />Mailer is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>. The licensor cannot revoke these freedoms as long as you follow the license terms:

* __Attribution__ — You must give __appropriate credit__

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.chon-group</groupId>
<artifactId>Mailer</artifactId>
<version>24.3.15</version>
<version>24.5.18</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/group/chon/agent/mailer/Mailer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import group.chon.agent.mailer.core.Util;
import jason.asSemantics.Message;
import jason.architecture.AgArch;

import java.util.ArrayList;

public class Mailer extends AgArch {
Expand All @@ -24,7 +23,6 @@ public void sendMsg(Message m){
this.emailBridge.sendMsg(m.getReceiver(),m.getIlForce(),m.getPropCont().toString());
}else{
this.getTS().getLogger().warning(Info.eMailProviderConfigurationNOTFOUND("sendMsg"));
//System.out.println(Info.eMailProviderConfigurationNOTFOUND("sendMsg"));
}
}else{
try {
Expand Down
38 changes: 5 additions & 33 deletions src/main/java/group/chon/agent/mailer/core/EMailMiddleware.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.ArrayList;
import java.util.Properties;
import java.util.concurrent.ThreadLocalRandom;
import java.util.logging.Logger;
import javax.mail.*;
import javax.mail.internet.*;
Expand All @@ -15,17 +14,11 @@ public class EMailMiddleware{
private String password;
private boolean Sauth, Sstarttls, Ssslenable,Rauth, Rstarttls, Rsslenable;
private String Sssltrust,Ssslprotocol,Rssltrust,Rsslprotocol;

private boolean RHostEnable = false;
private boolean RPropsEnable = false;

private boolean SPropsEnable = false;
private boolean SHostEnable = false;

private long lastChecked = 0;

//private String mailerName = "Mailer";

private Logger logger;

private final Util util = new Util();
Expand Down Expand Up @@ -99,15 +92,9 @@ public ArrayList<jason.asSemantics.Message> checkEMail() {
Folder[] allFolders = store.getDefaultFolder().list("*");
// Looking for Message in each folder
for(int i=0; i<allFolders.length; i++){
// Open the inbox folder and get the messages
//Folder inbox = store.getFolder("INBOX");
//inbox.open(Folder.READ_WRITE);
allFolders[i].open(Folder.READ_WRITE);
//javax.mail.Message[] messages = inbox.getMessages();
javax.mail.Message[] messages = allFolders[i].getMessages();
// Loop through the messages and printing info
for (Message message : messages) {
//Skip messages marked for deletion
if (message.getFlags().contains(Flags.Flag.DELETED) || message.getFlags().contains(Flags.Flag.SEEN)) {
continue;
}else{
Expand All @@ -127,7 +114,6 @@ public ArrayList<jason.asSemantics.Message> checkEMail() {
null,
util.getKqmlMessage());
jMsg.add(jasonMsgs);
//mark message for deletion
message.setFlag(Flags.Flag.DELETED, true);
}catch (Exception exception){
this.logger.severe("Something is wrong with the message!");
Expand All @@ -136,10 +122,8 @@ public ArrayList<jason.asSemantics.Message> checkEMail() {
}
}
if (Rprotocol.contains("imap")) {
//inbox.expunge();
allFolders[i].expunge();
}
//inbox.close();
allFolders[i].close();
}
store.close();
Expand Down Expand Up @@ -169,15 +153,13 @@ public ArrayList<jason.asSemantics.Message> checkEMail() {
}


public static String addressToString(Address[] rawAddress) {
//Check if address is not null and convert it to regular addresses
if (rawAddress != null) {
return rawAddress[0].toString();
} else return "null";
}
// public static String addressToString(Address[] rawAddress) {
// if (rawAddress != null) {
// return rawAddress[0].toString();
// } else return "null";
// }

public void sendMsg(String recipientEmail, String subject, String message) {
//Session session;
Session session = null;
Properties props = sslProps();

Expand All @@ -196,28 +178,22 @@ protected PasswordAuthentication getPasswordAuthentication() {
});
}catch (Exception e){
this.logger.severe("Connection error:" + e);
//System.out.println("["+this.mailerName+"] Connection error:" + e);
return;
}

try {
// Create a new message
Message msg = new MimeMessage(session);

// Set the recipient, subject, and message content
msg.setFrom(new InternetAddress(login));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipientEmail));
msg.setSubject(subject);
msg.setText(message);

// Send the message
Transport.send(msg,login,password);

this.logger.info("Email to "+recipientEmail+" sent successfully!");
//System.out.println("["+this.mailerName +"] Email to "+recipientEmail+" sent successfully!");
}catch (MessagingException e) {
this.logger.severe("Error sending email: " + e.getMessage());
//System.out.println("["+this.mailerName +"] Error sending email: " + e.getMessage());
if(e.getMessage().equals("535 Authentication credentials invalid")){
setLogin(null);
setPassword(null);
Expand Down Expand Up @@ -297,10 +273,6 @@ public boolean isRPropsEnable() {
return RPropsEnable;
}

// public void setMailerName(String mailerName){
// this.mailerName = mailerName;
// }

public boolean isSPropsEnable() {
return SPropsEnable;
}
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/group/chon/agent/mailer/core/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import jason.asSyntax.ASSyntax;
import jason.asSyntax.Plan;
import jason.asSyntax.Term;
import jason.asSyntax.parser.ParseException;
import org.jsoup.*;
import org.jsoup.nodes.*;

import javax.mail.Address;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMultipart;
Expand All @@ -18,9 +16,7 @@
public class Util {
private String kqmlMessage;
private String kqmlILF;

private String sender;

private Term term;

private boolean setKqmlMessage(String kqmlMessage) {
Expand Down Expand Up @@ -73,9 +69,6 @@ public String getSender() {
}

private String stripHTML(String html) {
//String text = html.replaceAll("<[^>]*>", "");
//text = text.replaceAll("\\s+", " ");
//return text;
Document doc = Jsoup.parse(html);
return doc.text();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package group.chon.agent.mailer.jasonStdLib;

import group.chon.agent.mailer.Mailer;
//import group.chon.agent.mailer.core.MailerTS;
import group.chon.agent.mailer.core.Info;
import jason.asSemantics.DefaultInternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Term;

public class credentials extends DefaultInternalAction {
//MailerTS mailerTS = null;


@Override
public Object execute(final TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Expand All @@ -19,7 +18,6 @@ public Object execute(final TransitionSystem ts, Unifier un, Term[] args) throws
mailerArch.getEmailBridge().setLogger(ts.getLogger());
mailerArch.getEmailBridge().setLogin(args[0].toString().replaceAll("\"",""));
mailerArch.getEmailBridge().setPassword(args[1].toString().replaceAll("\"",""));
//mailerArch.getEmailBridge().setMailerName(mailerArch.getAgName());
return true;
}else {
ts.getLogger().warning(Info.wrongParametersERROR(this.getClass().getName()));
Expand All @@ -29,16 +27,5 @@ public Object execute(final TransitionSystem ts, Unifier un, Term[] args) throws
ts.getLogger().warning(Info.nonMailerAgentERROR(this.getClass().getName()));
return false;
}
// if (args.length == 2) {
// mailerTS = new MailerTS(ts.getAg(), ts.getC(), ts.getSettings(), ts.getAgArch());
//
// mailerTS.getMailerArch().getEmailBridge().setLogin(args[0].toString().replaceAll("\"",""));
// mailerTS.getMailerArch().getEmailBridge().setPassword(args[1].toString().replaceAll("\"",""));
// mailerTS.getMailerArch().getEmailBridge().setMailerName(mailerTS.getAgArch().getAgName());
//
// return true;
// } else {
// return false;
// }
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package group.chon.agent.mailer.jasonStdLib;

import group.chon.agent.mailer.Mailer;
//import group.chon.agent.mailer.core.MailerTS;
import group.chon.agent.mailer.core.Info;
import jason.asSemantics.DefaultInternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Term;

public class eMailService extends DefaultInternalAction {
// MailerTS mailerTS = null;

@Override
public Object execute(final TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Expand Down Expand Up @@ -62,45 +60,6 @@ public Object execute(final TransitionSystem ts, Unifier un, Term[] args) throws
ts.getLogger().warning(Info.nonMailerAgentERROR(this.getClass().getName()));
return false;
}
// mailerTS = new MailerTS(ts.getAg(), ts.getC(), ts.getSettings(), ts.getAgArch());
// if (args.length == 2) {
// String[] input = parseString(args[0].toString());
// String[] output = parseString(args[1].toString());
//
// if(input[1].equals("imaps")){
// mailerTS.getMailerArch().getEmailBridge().setRAuth(
// false,
// true,
// false,
// "null",
// "null");
// mailerTS.getMailerArch().getEmailBridge().setReceiverProps(
// input[0].toString(),
// input[1].toString(),
// "993");
// }else{
// return false;
// }
//
// if(output[1].equals("smtpOverTLS")){
// mailerTS.getMailerArch().getEmailBridge().setSendAuth(
// true,
// true,
// false,
// "null",
// "null");
// mailerTS.getMailerArch().getEmailBridge().setSendProps(
// output[0].toString(),
// "smtp",
// "465"
// );
// }else{
// return false;
// }
// return true;
// } else {
// return false;
// }
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package group.chon.agent.mailer.jasonStdLib;

import group.chon.agent.mailer.Mailer;
//import group.chon.agent.mailer.core.MailerTS;
import group.chon.agent.mailer.core.Info;
import jason.asSemantics.DefaultInternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Term;

public class receiveEMail extends DefaultInternalAction {
//MailerTS mailerTS = null;

@Override
public Object execute(final TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Expand Down Expand Up @@ -38,13 +36,5 @@ public Object execute(final TransitionSystem ts, Unifier un, Term[] args) throws
ts.getLogger().warning(Info.nonMailerAgentERROR(this.getClass().getName()));
return false;
}
// mailerTS = new MailerTS(ts.getAg(), ts.getC(), ts.getSettings(), ts.getAgArch());
// if (args.length == 2) {
// mailerTS.getMailerArch().getEmailBridge().setLogin(args[0].toString());
// mailerTS.getMailerArch().getEmailBridge().setPassword(args[1].toString());
// }
// mailerTS.getMailerArch().getEMailMessage();
// return true;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import group.chon.agent.mailer.Mailer;
import group.chon.agent.mailer.core.Info;
//import group.chon.agent.mailer.core.MailerTS;
import jason.asSemantics.DefaultInternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Term;

public class receivingHost extends DefaultInternalAction {
//MailerTS mailerTS = null;

@Override
public Object execute(final TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Expand All @@ -30,16 +28,5 @@ public Object execute(final TransitionSystem ts, Unifier un, Term[] args) throws
ts.getLogger().warning(Info.nonMailerAgentERROR(this.getClass().getName()));
return false;
}
// if (args.length == 3) {
// mailerTS = new MailerTS(ts.getAg(), ts.getC(), ts.getSettings(), ts.getAgArch());
//
// mailerTS.getMailerArch().getEmailBridge().setReceiverProps(
// args[0].toString().replaceAll("\"",""),
// args[1].toString().replaceAll("\"",""),
// args[2].toString().replaceAll("\"",""));
// return true;
// } else {
// return false;
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import group.chon.agent.mailer.Mailer;
import group.chon.agent.mailer.core.Info;
//import group.chon.agent.mailer.core.MailerTS;
import jason.asSemantics.DefaultInternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Term;

public class receivingProperties extends DefaultInternalAction {
//MailerTS mailerTS = null;

@Override
public Object execute(final TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Expand All @@ -32,17 +30,5 @@ public Object execute(final TransitionSystem ts, Unifier un, Term[] args) throws
ts.getLogger().warning(Info.nonMailerAgentERROR(this.getClass().getName()));
return false;
}
// mailerTS = new MailerTS(ts.getAg(), ts.getC(), ts.getSettings(), ts.getAgArch());
// if (args.length == 5) {
// mailerTS.getMailerArch().getEmailBridge().setRAuth(
// Boolean.parseBoolean(args[0].toString().replaceAll("\"","")),
// Boolean.parseBoolean(args[1].toString().replaceAll("\"","")),
// Boolean.parseBoolean(args[2].toString().replaceAll("\"","")),
// args[3].toString().replaceAll("\"",""),
// args[4].toString().replaceAll("\"",""));
// return true;
// } else {
// return false;
// }
}
}
Loading

0 comments on commit 0cfe4ba

Please sign in to comment.