diff options
author | Sebastian Reichel <sre@ring0.de> | 2013-05-16 00:30:12 +0200 |
---|---|---|
committer | Sebastian Reichel <sre@ring0.de> | 2013-05-16 00:30:12 +0200 |
commit | e075f9d8060bb08da46fd2be679e2cc2f226fec1 (patch) | |
tree | 8a153225dc6219de6835e461dd7921c817978bd2 | |
parent | 73969b46fbeafd31d2c0a31f4e4a3c482e2bf2fe (diff) | |
download | serial-barcode-scanner-e075f9d8060bb08da46fd2be679e2cc2f226fec1.tar.bz2 |
implement mail sending queue
-rw-r--r-- | src/mail/mailer.vala | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/mail/mailer.vala b/src/mail/mailer.vala index 756a131..e4b1c6d 100644 --- a/src/mail/mailer.vala +++ b/src/mail/mailer.vala @@ -24,6 +24,7 @@ public class MailerImplementation { MailImplementation mail; } + Queue<MailImplementation> send_queue; HashTable<string,MailEntry?> mails; MailImplementation? current_mail; @@ -62,6 +63,7 @@ public class MailerImplementation { Smtp.auth_client_init(); session = Smtp.Session(); mails = new HashTable<string,MailEntry?>(str_hash, str_equal); + send_queue = new Queue<MailImplementation>(); /* ignore SIGPIPE, as suggested by libESMTP */ Posix.signal(Posix.SIGPIPE, Posix.SIG_IGN); @@ -136,16 +138,19 @@ public class MailerImplementation { if(!(path in mails)) throw new IOError.NOT_FOUND("No such mail"); - if(current_mail != null) - throw new IOError.BUSY("Mail system is busy"); + send_queue.push_tail(mails[path].mail); + delete_mail(path); - current_mail = mails[path].mail; Idle.add(send_mail_background); - delete_mail(path); } private bool send_mail_background() { + current_mail = send_queue.pop_head(); + + if(current_mail == null) + return false; + var message = session.add_message(); messagecb_done = false; @@ -166,7 +171,7 @@ public class MailerImplementation { current_mail = null; - /* do not run again */ - return false; + /* call method again, queue may not be empty */ + return true; } } |