diff --git a/plugins/extras/p5.mail/Pop3.cs b/plugins/extras/p5.mail/Pop3.cs index 82ff6da4..063f70ef 100644 --- a/plugins/extras/p5.mail/Pop3.cs +++ b/plugins/extras/p5.mail/Pop3.cs @@ -72,12 +72,12 @@ public static void p5_pop3_get (ApplicationContext context, ActiveEventArgs e) // Making sure we're able to post QUIT signal when done, regardless of what happens inside of this code. try { - // Figuring out how many messages to retrieve, defaulting to "5" if not explicitly told something else by caller, + // Figuring out how many messages to retrieve, defaulting to "5", if not explicitly told something else by caller, // making sure we never try to retrieve more messages than server actually has. - int noMessages = Math.Min (client.Count, e.Args.GetExChildValue ("count", context, 5)); + var noMessages = Math.Min (client.Count, e.Args.GetExChildValue ("count", context, 5)); // Fetching messages from server, but not any more messages than caller requested, or number of available messages. - for (int idxMsg = 0; idxMsg < noMessages; idxMsg++) { + for (var idxMsg = 0; idxMsg < noMessages; idxMsg++) { // Process message returned from POP3 server by building Node structure wrapping message. var msgNode = ProcessMessage ( @@ -103,6 +103,9 @@ public static void p5_pop3_get (ApplicationContext context, ActiveEventArgs e) // Invoking lambda callback, letting caller do his thing. context.RaiseEvent ("eval-mutable", lambda); } + + // Disconnecting from server, making sure we send the QUIT signal. + client.Disconnect (true); } catch { @@ -111,10 +114,6 @@ public static void p5_pop3_get (ApplicationContext context, ActiveEventArgs e) client.Disconnect (false); throw; - } finally { - - // Disconnecting from server, making sure we send the QUIT signal. - client.Disconnect (true); } } } diff --git a/plugins/extras/p5.mail/Smtp.cs b/plugins/extras/p5.mail/Smtp.cs index 2d701810..63aafbd0 100644 --- a/plugins/extras/p5.mail/Smtp.cs +++ b/plugins/extras/p5.mail/Smtp.cs @@ -79,10 +79,7 @@ public static void p5_smtp_send (ApplicationContext context, ActiveEventArgs e) /* * Sends all [envelopes] found. */ - static void SendMessages ( - ApplicationContext context, - Node args, - SmtpClient client) + static void SendMessages (ApplicationContext context, Node args, SmtpClient client) { // Looping through each message caller wants to send. foreach (var idxEnvelopeNode in args.Children.Where (ix => ix.Name == "envelope")) { @@ -113,10 +110,7 @@ static void SendMessages ( /* * Creates and decorates MimeMessage according to given args. */ - static MimeMessage CreateMessage ( - ApplicationContext context, - Node envelopeNode, - List streams) + static MimeMessage CreateMessage (ApplicationContext context, Node envelopeNode, List streams) { // Creating message to return. var message = new MimeMessage (); @@ -128,7 +122,7 @@ static MimeMessage CreateMessage ( DecorateMessageEnvelope (context, envelopeNode, message); // Retrieving [body] node of envelope, and doing basic syntax checking. - Node body = envelopeNode ["body"]; + var body = envelopeNode ["body"]; if (body == null) throw new LambdaException ( "No [body] found inside of [envelope]", @@ -148,10 +142,7 @@ static MimeMessage CreateMessage ( /* * Decorates headers of MimeMessage. */ - static void DecorateMessageEnvelope ( - ApplicationContext context, - Node args, - MimeMessage message) + static void DecorateMessageEnvelope (ApplicationContext context, Node args, MimeMessage message) { message.Subject = args.GetExChildValue ("Subject", context, ""); @@ -196,10 +187,7 @@ static void DecorateMessageEnvelope ( /* * Retrieves all emails beneath the args node's child with the given name. */ - static IEnumerable GetAddresses ( - ApplicationContext context, - Node args, - string name) + static IEnumerable GetAddresses (ApplicationContext context, Node args, string name) { // Checking there exist a node with supplied name on args. if (args [name] != null) { diff --git a/plugins/extras/p5.mail/helpers/Common.cs b/plugins/extras/p5.mail/helpers/Common.cs index 8bfe56ee..508f111d 100644 --- a/plugins/extras/p5.mail/helpers/Common.cs +++ b/plugins/extras/p5.mail/helpers/Common.cs @@ -49,22 +49,12 @@ public static string GetBaseFolder (ApplicationContext context) /// MailService type /// Active Event Arguments /// pop3 or smtp - public static void ConnectServer ( - ApplicationContext context, - MailService client, - Node args, - string serverType) + public static void ConnectServer (ApplicationContext context, MailService client, Node args, string serverType) { // Retrieving server settings, defaulting to those found in web.config, if not explicitly overridden. - string server = - args.GetExChildValue ("server", context) ?? - "localhost"; - int port = args ["port"] != null ? - args.GetExChildValue ("port", context) : - 25; - bool useSsl = args ["ssl"] != null ? - args.GetExChildValue ("ssl", context) : - false; + var server = args.GetExChildValue ("server", context, "localhost"); + var port = args.GetExChildValue ("port", context, 25); + bool useSsl = args.GetExChildValue ("ssl", context, false); // Connecting client to server client.Connect ( @@ -75,20 +65,10 @@ public static void ConnectServer ( // Fuck OATH2!! [quote; its creator!] client.AuthenticationMechanisms.Remove ("XOAUTH2"); - // Finding username and password to use to authenticate - string username = null, password = null; - - // Checking if caller supplied username and password, and if so, using those credentials - if (args ["username"] != null) { - - // Notice, this logic allows caller to supply null or empty password, in case specified server does - // not require authorisation to send emails, in which case, client.Authenticate below will never be invoked! - username = args.GetExChildValue ("username", context, ""); - password = args.GetExChildValue ("password", context, ""); - - // Authenticating, unless username is empty or null - if (!string.IsNullOrEmpty (username)) - client.Authenticate (username, password); + // Authenticating user, if credentials were supplied. + var username = args.GetExChildValue ("username", context, ""); + if (!string.IsNullOrEmpty (username)) { + client.Authenticate (username, args.GetExChildValue ("password", context, "")); } } }