summaryrefslogtreecommitdiffstats
path: root/src/mail
diff options
context:
space:
mode:
Diffstat (limited to 'src/mail')
-rw-r--r--src/mail/.gitignore1
-rw-r--r--src/mail/Makefile10
-rw-r--r--src/mail/mail.vala58
-rw-r--r--src/mail/mailer-interface.vala14
-rw-r--r--src/mail/mailer.vala34
-rw-r--r--src/mail/main.vala15
6 files changed, 67 insertions, 65 deletions
diff --git a/src/mail/.gitignore b/src/mail/.gitignore
deleted file mode 100644
index f2ae723..0000000
--- a/src/mail/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-mailer
diff --git a/src/mail/Makefile b/src/mail/Makefile
deleted file mode 100644
index 6ec153c..0000000
--- a/src/mail/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
-all: mailer
- @echo > /dev/null
-
-mailer: main.vala mailer.vala mail.vala mailer-interface.vala ../config/config-interface.vala
- valac -X -w -o $@ --vapidir=../../vapi --pkg posix --pkg libesmtp --pkg gio-2.0 --pkg gmime-2.6 -X -D_GNU_SOURCE -X -lesmtp -X -lssl -X -lcrypto -X -ldl -X -pthread $^
-
-clean:
- rm -f mailer
-
-.PHONY: all clean
diff --git a/src/mail/mail.vala b/src/mail/mail.vala
index 41153f8..f6cedc0 100644
--- a/src/mail/mail.vala
+++ b/src/mail/mail.vala
@@ -19,16 +19,18 @@ public class MailImplementation {
private GMime.Part? main_text = null;
private GMime.Part? main_html = null;
private GMime.Part[] attachments;
+ private DateTime gdate;
- private GMime.FilterCRLF filter;
+ private GMime.FilterUnix2Dos filter_unix2dos;
+ private GMime.FilterSmtpData filter_smtp;
private string[] recipients;
private string? reversepath;
public MailContact from { set {
- string sender = value.name + " " + "<" + value.email + ">";
reversepath = value.email;
- m.set_sender(sender);
+ m.add_mailbox(GMime.AddressType.SENDER, value.name, value.email);
+ m.add_mailbox(GMime.AddressType.FROM, value.name, value.email);
}}
public string subject {
@@ -37,7 +39,7 @@ public class MailImplementation {
return (result == null) ? "" : result;
}
set {
- m.set_subject(value);
+ m.set_subject(value, "utf-8");
}
}
@@ -53,30 +55,36 @@ public class MailImplementation {
public string reply_to {
owned get {
- var result = m.get_reply_to();
+ var result = m.get_reply_to().to_string(new GMime.FormatOptions(), true);
return (result == null) ? "" : result;
}
set {
- m.set_reply_to(value);
+ m.add_mailbox(GMime.AddressType.REPLY_TO, "", value);
}
}
public MailDate date {
owned get {
MailDate result = {};
- m.get_date(out result.date, out result.tz_offset);
+ result.timezone = this.gdate.get_timezone_abbreviation();
+ result.date = this.gdate.to_unix();
return result;
}
set {
- m.set_date((ulong) value.date, value.tz_offset);
+ var timezone = new TimeZone(value.timezone);
+ this.gdate = new DateTime.from_unix_utc((int64) value.date).to_timezone(timezone);
+ m.set_date(this.gdate);
}
}
public MailImplementation() {
m = new GMime.Message(true);
- m.set_header("X-Mailer", "KtT Shopsystem");
+ m.set_header("X-Mailer", "KtT Shopsystem", "utf-8");
+ this.gdate = new DateTime.now_local();
+ m.set_date(this.gdate);
attachments = new GMime.Part[0];
- filter = new GMime.FilterCRLF(true, true);
+ filter_smtp = new GMime.FilterSmtpData();
+ filter_unix2dos = new GMime.FilterUnix2Dos(true);
recipients = new string[0];
}
@@ -89,41 +97,37 @@ public class MailImplementation {
public void set_subject(string subject) {
m.set_subject(subject);
}
-
- public void set_date(uint64 date, int tz_offset) {
- m.set_date((ulong) date, tz_offset);
- }
#endif
- public void add_recipient(MailContact contact, GMime.RecipientType type) {
- m.add_recipient(type, contact.name, contact.email);
+ public void add_recipient(MailContact contact, GMime.AddressType type) throws DBusError, IOError {
+ m.add_mailbox(type, contact.name, contact.email);
recipients += contact.email;
}
- public void set_main_part(string text, MessageType type) {
+ public void set_main_part(string text, MessageType type) throws DBusError, IOError {
GMime.DataWrapper content = new GMime.DataWrapper.with_stream(
new GMime.StreamMem.with_buffer(text.data),
GMime.ContentEncoding.DEFAULT);
GMime.Part? part = new GMime.Part();
- part.set_content_object(content);
+ part.set_content(content);
switch(type) {
case MessageType.HTML:
- part.set_content_type(new GMime.ContentType.from_string("text/html; charset=utf-8"));
+ part.set_content_type(GMime.ContentType.parse(new GMime.ParserOptions(), "text/html; charset=utf-8"));
part.set_content_encoding(part.get_best_content_encoding(GMime.EncodingConstraint.7BIT));
main_html = part;
break;
case MessageType.PLAIN:
default:
- part.set_content_type(new GMime.ContentType.from_string("text/plain; charset=utf-8; format=flowed"));
+ part.set_content_type(GMime.ContentType.parse(new GMime.ParserOptions(), "text/plain; charset=utf-8; format=flowed"));
part.set_content_encoding(part.get_best_content_encoding(GMime.EncodingConstraint.7BIT));
main_text = part;
break;
}
}
- public void add_attachment(string filename, string content_type, uint8[] data) {
+ public void add_attachment(string filename, string content_type, uint8[] data) throws DBusError, IOError {
GMime.Part part = new GMime.Part();
GMime.DataWrapper content = new GMime.DataWrapper.with_stream(
@@ -133,8 +137,8 @@ public class MailImplementation {
/* configure part */
part.set_disposition("attachment");
part.set_filename(filename);
- part.set_content_type(new GMime.ContentType.from_string(content_type));
- part.set_content_object(content);
+ part.set_content_type(GMime.ContentType.parse(new GMime.ParserOptions(), content_type));
+ part.set_content(content);
part.set_content_encoding(part.get_best_content_encoding(GMime.EncodingConstraint.7BIT));
attachments += part;
@@ -190,11 +194,13 @@ public class MailImplementation {
[DBus (visible = false)]
public string generate() {
update_mime_part();
- string result = m.to_string();
+ string result = m.to_string(new GMime.FormatOptions());
uint8[] crlfdata;
+ uint8[] smtpdata;
size_t prespace;
- filter.filter(result.data, 0, out crlfdata, out prespace);
- return (string) crlfdata;
+ filter_unix2dos.filter(result.data, 0, out crlfdata, out prespace);
+ filter_smtp.filter(crlfdata, 0, out smtpdata, out prespace);
+ return (string) smtpdata;
}
[DBus (visible = false)]
diff --git a/src/mail/mailer-interface.vala b/src/mail/mailer-interface.vala
index 54b4865..019585b 100644
--- a/src/mail/mailer-interface.vala
+++ b/src/mail/mailer-interface.vala
@@ -15,9 +15,9 @@
[DBus (name = "io.mainframe.shopsystem.Mailer")]
public interface Mailer : Object {
- public abstract string create_mail() throws IOError;
- public abstract void delete_mail(string path) throws IOError;
- public abstract void send_mail(string path) throws IOError;
+ public abstract string create_mail() throws IOError, DBusError;
+ public abstract void delete_mail(string path) throws IOError, DBusError;
+ public abstract void send_mail(string path) throws IOError, DBusError;
}
[DBus (name = "io.mainframe.shopsystem.Mail")]
@@ -28,9 +28,9 @@ public interface Mail : Object {
public abstract string reply_to { owned get; set; }
public abstract MailDate date { owned get; set; }
- public abstract void add_recipient(MailContact contact, RecipientType type = RecipientType.TO) throws IOError;
- public abstract void set_main_part(string text, MessageType type = MessageType.PLAIN) throws IOError;
- public abstract void add_attachment(string filename, string content_type, uint8[] data) throws IOError;
+ public abstract void add_recipient(MailContact contact, RecipientType type = RecipientType.TO) throws IOError, DBusError;
+ public abstract void set_main_part(string text, MessageType type = MessageType.PLAIN) throws IOError, DBusError;
+ public abstract void add_attachment(string filename, string content_type, uint8[] data) throws IOError, DBusError;
}
public struct MailAttachment {
@@ -51,7 +51,7 @@ public struct MailContact {
public struct MailDate {
uint64 date;
- int tz_offset;
+ string timezone;
}
public enum MessageType {
diff --git a/src/mail/mailer.vala b/src/mail/mailer.vala
index 3ec9381..642ceaa 100644
--- a/src/mail/mailer.vala
+++ b/src/mail/mailer.vala
@@ -56,10 +56,10 @@ public class MailerImplementation {
return 1;
}
- public MailerImplementation() throws IOError {
+ public MailerImplementation() throws DBusError, IOError {
int result;
- GMime.init(0);
+ GMime.init();
Smtp.auth_client_init();
session = Smtp.Session();
@@ -67,7 +67,7 @@ public class MailerImplementation {
send_queue = new Queue<MailImplementation>();
/* ignore SIGPIPE, as suggested by libESMTP */
- Posix.signal(Posix.SIGPIPE, Posix.SIG_IGN);
+ Posix.signal(Posix.Signal.PIPE, Posix.SIG_IGN);
/* get configuration */
Config config = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config");
@@ -76,7 +76,7 @@ public class MailerImplementation {
var cfgport = config.get_integer("MAIL", "port");
server = @"$cfgserv:$cfgport";
} catch(KeyFileError e) {
- throw new IOError.FAILED("server or port configuration is missing");
+ throw new IOError.FAILED(_("server or port configuration is missing"));
}
try {
@@ -96,7 +96,7 @@ public class MailerImplementation {
/* setup server */
result = session.set_server(server);
if(result == 0)
- throw new IOError.FAILED("could not setup server");
+ throw new IOError.FAILED(_("could not setup server"));
/* Use TLS if possible */
if (starttls)
@@ -104,7 +104,7 @@ public class MailerImplementation {
else
result = session.starttls_enable(Smtp.StartTlsOption.DISABLED);
if(result == 0)
- throw new IOError.FAILED("could not configure STARTTLS");
+ throw new IOError.FAILED(_("could not configure STARTTLS"));
/* setup authentication */
if(username != "") {
@@ -120,7 +120,7 @@ public class MailerImplementation {
GMime.shutdown();
}
- public string create_mail() throws IOError {
+ public string create_mail() throws DBusError, IOError {
string path = @"/io/mainframe/shopsystem/mail/$mailcounter";
var mail = new MailImplementation();
@@ -136,17 +136,17 @@ public class MailerImplementation {
return path;
}
- public void delete_mail(string path) throws IOError {
+ public void delete_mail(string path) throws DBusError, IOError {
if(!(path in mails))
- throw new IOError.NOT_FOUND("No such mail");
+ throw new IOError.NOT_FOUND(_("No such mail"));
mail_bus.unregister_object(mails[path].registration_id);
mails.remove(path);
}
- public void send_mail(string path) throws IOError {
+ public void send_mail(string path) throws DBusError, IOError {
if(!(path in mails))
- throw new IOError.NOT_FOUND("No such mail");
+ throw new IOError.NOT_FOUND(_("No such mail"));
send_queue.push_tail(mails[path].mail);
delete_mail(path);
@@ -172,12 +172,16 @@ public class MailerImplementation {
message.set_reverse_path(current_mail.get_reverse_path());
int result = session.start_session();
- if(result == 0)
- throw new IOError.FAILED("eSMTP: Start Session failed!");
+ if(result == 0) {
+ stderr.printf(_("eSMTP: Start Session failed!"));
+ return false;
+ }
unowned Smtp.Status status = message.transfer_status();
- if(status.code < 200 || status.code >= 300)
- throw new IOError.FAILED("Reply from SMTP-Server: %s", status.text);
+ if(status.code < 200 || status.code >= 300) {
+ stderr.printf(_("Reply from SMTP-Server: %s"));
+ return false;
+ }
current_mail = null;
diff --git a/src/mail/main.vala b/src/mail/main.vala
index 0c36f6b..b3a7088 100644
--- a/src/mail/main.vala
+++ b/src/mail/main.vala
@@ -17,30 +17,33 @@ MailerImplementation m;
DBusConnection mail_bus;
public static int main(string[] args) {
+ Intl.setlocale(LocaleCategory.ALL, "");
+ Intl.textdomain("shopsystem");
+
try {
m = new MailerImplementation();
- } catch(IOError e) {
- stderr.printf("Error: %s\n", e.message);
+ } catch(Error e) {
+ stderr.printf(_("Error: %s\n"), e.message);
}
Bus.own_name(
BusType.SYSTEM,
"io.mainframe.shopsystem.Mail",
BusNameOwnerFlags.NONE,
- on_mail_bus_aquired,
+ on_mail_bus_acquired,
() => {},
- () => stderr.printf("Error: Could not aquire name\n"));
+ () => stderr.printf(_("Error: Could not acquire name\n")));
new MainLoop().run();
return 0;
}
-void on_mail_bus_aquired(DBusConnection con) {
+void on_mail_bus_acquired(DBusConnection con) {
try {
mail_bus = con;
con.register_object("/io/mainframe/shopsystem/mailer", m);
} catch(IOError e) {
- stderr.printf("Error: Could not register service\n");
+ stderr.printf(_("Error: Could not register service\n"));
}
}