/// <summary> /// Unsubscribe a newline-separated list of addresses. /// </summary> /// <param name="addresses"></param> /// <param name="options"></param> /// <returns></returns> public async Task <UnsubscribeResult> UnsubscribeAsync(string addresses, UnsubscribeOptions options = UnsubscribeOptions.None) { var result = new UnsubscribeResult(); if (!String.IsNullOrWhiteSpace(addresses)) { var req = new RestRequest(Method.POST); req.AddParameter("unsubscribees", addresses); req.AddParameter("send_unsub_ack_to_this_batch", options.HasFlag(UnsubscribeOptions.SendAcknowledgement).ToInt()); req.AddParameter("send_unsub_notifications_to_list_owner", options.HasFlag(UnsubscribeOptions.NotifyOwner).ToInt()); var resp = await this.GetClient().ExecuteAdminRequestAsync(_removePage, req).ConfigureAwait(false); var doc = resp.Content.GetHtmlDocument(); string xpath = "//h5[contains(translate(text(), 'SU', 'su'), 'successfully unsubscribed')]/following-sibling::ul[1]/li"; foreach (var node in doc.DocumentNode.SafeSelectNodes(xpath)) { result.Unsubscribed.Add(node.InnerText.Trim()); } xpath = "//h3[descendant::*[contains(translate(text(), 'CU', 'cu'), 'cannot unsubscribe')]]/following-sibling::ul[1]/li"; foreach (var node in doc.DocumentNode.SafeSelectNodes(xpath)) { result.NonMembers.Add(node.InnerText.Trim()); } if (_emailListPopulated) { await PopulateEmailListAsync().ConfigureAwait(false); } } return(result); }
public async Task Unsubscribe_Sends_Right_Params(UnsubscribeOptions options) { await _list.Membership.UnsubscribeAsync("foo", options); var ack = options.HasFlag(UnsubscribeOptions.SendAcknowledgement); var owner = options.HasFlag(UnsubscribeOptions.NotifyOwner); _request.Should().NotBeNull(); _parmStrings.Should().Contain("unsubscribees=foo"); _parmStrings.Should().Contain($"send_unsub_ack_to_this_batch={ack.ToInt()}"); _parmStrings.Should().Contain($"send_unsub_notifications_to_list_owner={owner.ToInt()}"); }
public UnsubscribeResult Unsubscribe(string members, UnsubscribeOptions options = UnsubscribeOptions.None) { var result = new UnsubscribeResult(); if (!String.IsNullOrWhiteSpace(members)) { var req = new RestRequest(); req.AddParameter("unsubscribees", members); req.AddParameter("send_unsub_ack_to_this_batch", options.HasFlag(UnsubscribeOptions.SendAcknowledgement).ToInt()); req.AddParameter("send_unsub_notifications_to_list_owner", options.HasFlag(UnsubscribeOptions.NotifyOwner).ToInt()); var resp = this.GetClient().ExecutePostAdminRequest(_removePage, req); var doc = GetHtmlDocument(resp.Content); string xpath = "//h5[contains(translate(text(), 'SU', 'su'), 'successfully unsubscribed')]/following-sibling::ul[1]/li"; foreach (var node in doc.DocumentNode.SafeSelectNodes(xpath)) result.Unsubscribed.Add(node.InnerText.Trim()); xpath = "//h3[descendant::*[contains(translate(text(), 'CU', 'cu'), 'cannot unsubscribe')]]/following-sibling::ul[1]/li"; foreach (var node in doc.DocumentNode.SafeSelectNodes(xpath)) result.NonMembers.Add(node.InnerText.Trim()); if (_emailListPopulated) PopulateEmailList(); } return result; }