Exemplo n.º 1
0
        public async Task Execute(IJobExecutionContext context)
        {
            string username = context.MergedJobDataMap.GetString("username");
            string email    = context.MergedJobDataMap.GetString("email");

            var service             = api.GetGmailService(username);
            var forwardingAddresses = await service.Users.Settings.ForwardingAddresses.List(username).ExecuteAsync();

            var existing = (forwardingAddresses?.ForwardingAddresses ?? new List <ForwardingAddress>())
                           .FirstOrDefault(f => f.ForwardingEmail.Equals(email, StringComparison.OrdinalIgnoreCase));

            if (existing.VerificationStatus != "accepted")
            {
                logger.LogInformation($"Waiting for {username} to accept forwarding address");
                context.JobDetail.JobDataMap.Put("_refire", 30);
            }
        }
Exemplo n.º 2
0
        public async Task Execute(IJobExecutionContext context)
        {
            string username = context.MergedJobDataMap.GetString("username");
            string email    = context.MergedJobDataMap.GetString("email");

            var service = api.GetGmailService(username);
            var forward = await service.Users.Settings.GetAutoForwarding(username).ExecuteAsync();

            if (forward.Disposition != "trash" || !forward.EmailAddress.Equals(email, StringComparison.OrdinalIgnoreCase) || !(forward.Enabled ?? false))
            {
                logger.LogInformation("Setting forwarding address for " + username);
                await service.Users.Settings.UpdateAutoForwarding(new AutoForwarding
                {
                    Disposition  = "trash",
                    EmailAddress = email,
                    Enabled      = true
                }, username).ExecuteAsync();
            }
        }
Exemplo n.º 3
0
        public async Task Execute(IJobExecutionContext context)
        {
            string username = context.MergedJobDataMap.GetString("username");
            string email    = context.MergedJobDataMap.GetString("email");

            try
            {
                var service             = api.GetGmailService(username);
                var forwardingAddresses = await service.Users.Settings.ForwardingAddresses.List(username).ExecuteAsync();

                var existing = (forwardingAddresses?.ForwardingAddresses ?? new List <ForwardingAddress>())
                               .FirstOrDefault(f => f.ForwardingEmail.Equals(email, StringComparison.OrdinalIgnoreCase));
                if (existing == null)
                {
                    logger.LogInformation("Adding forwarding address to " + username);
                    await service.Users.Settings.ForwardingAddresses.Create(new ForwardingAddress { ForwardingEmail = email }, username).ExecuteAsync();
                }
            }
            catch (TokenResponseException e)
            {
                logger.LogWarning("Need to reschedule job.", e);
                context.JobDetail.JobDataMap.Put("_refire", 10);
            }
        }