/// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            DescribeReceiptRuleSetResponse response = new DescribeReceiptRuleSetResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("DescribeReceiptRuleSetResult", 2))
                    {
                        UnmarshallResult(context, response);
                        continue;
                    }

                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context);
                    }
                }
            }

            return(response);
        }
        private static void UnmarshallResult(XmlUnmarshallerContext context, DescribeReceiptRuleSetResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            if (context.IsStartOfDocument)
            {
                targetDepth += 2;
            }

            while (context.ReadAtDepth(originalDepth))
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("Metadata", targetDepth))
                    {
                        var unmarshaller = ReceiptRuleSetMetadataUnmarshaller.Instance;
                        response.Metadata = unmarshaller.Unmarshall(context);
                        continue;
                    }
                    if (context.TestExpression("Rules/member", targetDepth))
                    {
                        var unmarshaller = ReceiptRuleUnmarshaller.Instance;
                        var item         = unmarshaller.Unmarshall(context);
                        response.Rules.Add(item);
                        continue;
                    }
                }
            }

            return;
        }
Example #3
0
        private void GetRules(string ruleset)
        {
            var response = sesclient.DescribeReceiptRuleSetAsync(new DescribeReceiptRuleSetRequest
            {
                RuleSetName = ruleset
            });

            try
            {
                DescribeReceiptRuleSetResponse result = response.Result;
                List <ReceiptRule>             rules  = result.Rules;
                foreach (ReceiptRule rule in rules)
                {
                    var recipients = rule.Recipients;
                    foreach (var recipient in recipients)
                    {
                        string[] parts   = recipient.Split('@');
                        var      actions = rule.Actions;
                        var      name    = parts[0];
                        var      domain  = parts[1];
                        string   bucket  = "";
                        string   topic   = "";
                        foreach (var action in actions)
                        {
                            try
                            {
                                bucket = action.S3Action.BucketName;
                                topic  = action.S3Action.TopicArn;
                            }
                            catch (AmazonSimpleEmailServiceException e)
                            {
                                Console.WriteLine("No Topic found in SES S3Action. Message: '{0}' ", e.Message);
                                if (topic == "")
                                {
                                    try
                                    {
                                        topic = action.SNSAction.TopicArn;
                                    }
                                    catch (AmazonSimpleEmailServiceException e1)
                                    {
                                        Console.WriteLine("No Topic available from SES SNSAction on {0}. Message:'{1}'", recipient, e1.Message);
                                    }
                                }
                            }
                        }
                        if (bucket != "" && topic != "")
                        {
                            var mbx = new FastEmailMailbox(name, domain, bucket, topic);
                            Mailboxes.Add(recipient, mbx);
                        }
                    }
                }
            }
            catch
            {
                Console.WriteLine("Unhandled exception while processing SES mailboxes");
            }
        }