public override void Close() { int num = 3; for (int i = 0; i < num; i++) { bool flag = i == num - 1; try { HeaderList headerList = new HeaderList(); headerList.Add("content-type", this.contentType); headerList.Add("x-amz-acl", "public-read"); this.s3OutputMethod.s3adaptor.put(this.s3OutputMethod.bucketName, this.s3key, new S3Content(this.ToArray()), headerList); break; } catch (WebException) { if (flag) { throw; } } catch (SoapException) { if (flag) { throw; } } } base.Close(); }
internal MimeMessage (ParserOptions options, IEnumerable<Header> headers) { addresses = new Dictionary<string, InternetAddressList> (icase); Headers = new HeaderList (options); // initialize our address lists foreach (var name in StandardAddressHeaders) { var list = new InternetAddressList (); list.Changed += InternetAddressListChanged; addresses.Add (name, list); } references = new MessageIdList (); references.Changed += ReferencesChanged; inreplyto = null; Headers.Changed += HeadersChanged; // add all of our message headers... foreach (var header in headers) { if (header.Field.StartsWith ("Content-", StringComparison.OrdinalIgnoreCase)) continue; Headers.Add (header); } }
public void TestReplacingHeaders() { const string ReplacedContentType = "text/plain; charset=iso-8859-1; name=body.txt"; const string ReplacedContentDisposition = "inline; filename=body.txt"; const string ReplacedContentId = "<content.id.2@localhost>"; var headers = new HeaderList (); headers.Add ("Content-Type", "text/plain"); headers.Add ("Content-Disposition", "attachment"); headers.Add ("Content-Id", "<content-id.1@localhost>"); headers.Replace ("Content-Disposition", ReplacedContentDisposition); Assert.AreEqual (3, headers.Count, "Unexpected number of headers after replacing Content-Disposition."); Assert.AreEqual (ReplacedContentDisposition, headers["Content-Disposition"], "Content-Disposition has unexpected value after replacing it."); Assert.AreEqual (1, headers.IndexOf ("Content-Disposition"), "Replaced Content-Disposition not in the expected position."); headers.Replace ("Content-Type", ReplacedContentType); Assert.AreEqual (3, headers.Count, "Unexpected number of headers after replacing Content-Type."); Assert.AreEqual (ReplacedContentType, headers["Content-Type"], "Content-Type has unexpected value after replacing it."); Assert.AreEqual (0, headers.IndexOf ("Content-Type"), "Replaced Content-Type not in the expected position."); headers.Replace ("Content-Id", ReplacedContentId); Assert.AreEqual (3, headers.Count, "Unexpected number of headers after replacing Content-Id."); Assert.AreEqual (ReplacedContentId, headers["Content-Id"], "Content-Id has unexpected value after replacing it."); Assert.AreEqual (2, headers.IndexOf ("Content-Id"), "Replaced Content-Id not in the expected position."); }
protected AuthenticationBase() { _Params = new HeaderList(); _AuthParams = new HeaderList(); _CurrentStep = 0; Reset(); }
/// <summary> /// Get the list of emails for a search /// </summary> /// <param name="args">The search condition followed by the header only and set as seen booleans</param> /// <returns>The list of mail message that match the search</returns> private List <MimeMessage> GetSearchResults(params object[] args) { List <MimeMessage> messageList = new List <MimeMessage>(); IMailFolder folder = this.GetCurrentFolder(); foreach (UniqueId uid in folder.Search((SearchQuery)args[0], default(CancellationToken))) { if ((bool)args[2]) { folder.AddFlags(uid, MessageFlags.Seen, true); } MimeMessage message = null; if ((bool)args[1]) { HeaderList headers = folder.GetHeaders(uid); message = new MimeMessage(headers); } else { message = folder.GetMessage(uid); } messageList.Add(message); } return(messageList); }
internal static bool ResubmitApprovedMessage(MessageItem messageItem, TransportMailItem transportMailItem, string approverAddress) { DateTime utcNow = DateTime.UtcNow; HeaderList headerList = (transportMailItem.RootPart != null) ? transportMailItem.RootPart.Headers : null; if (!ModerationHelper.RestoreOriginalMessage(messageItem, transportMailItem, TraceHelper.ModeratedTransportTracer, TraceHelper.MessageProbeActivityId)) { return(false); } transportMailItem.RootPart.Headers.RemoveAll("X-MS-Exchange-Organization-Approval-Approved"); TextHeader textHeader = (TextHeader)Header.Create("X-MS-Exchange-Organization-Approval-Approved"); textHeader.Value = (string)transportMailItem.Recipients[0].Email; foreach (MailRecipient mailRecipient in transportMailItem.Recipients) { if (mailRecipient.Status == Status.Ready) { textHeader.Value = (string)mailRecipient.Email; break; } } transportMailItem.RootPart.Headers.AppendChild(textHeader); if (transportMailItem.RootPart.Headers.FindFirst("X-MS-Exchange-Organization-Moderation-SavedArrivalTime") == null) { Header header = transportMailItem.RootPart.Headers.FindFirst("X-MS-Exchange-Organization-OriginalArrivalTime"); string value = null; if (header != null) { value = header.Value; } if (!string.IsNullOrEmpty(value)) { transportMailItem.RootPart.Headers.AppendChild(new AsciiTextHeader("X-MS-Exchange-Organization-Moderation-SavedArrivalTime", value)); } } TextHeader textHeader2 = (TextHeader)Header.Create("X-Moderation-Data"); ExDateTime?valueAsNullable = messageItem.GetValueAsNullable <ExDateTime>(MessageItemSchema.ApprovalDecisionTime); if (valueAsNullable != null) { textHeader2.Value = valueAsNullable.ToString(); transportMailItem.RootPart.Headers.AppendChild(textHeader2); } if (headerList != null) { Header[] array = headerList.FindAll(HeaderId.Received); foreach (Header header2 in array) { Header header3 = Header.Create(HeaderId.Received); header2.CopyTo(header3); transportMailItem.RootPart.Headers.PrependChild(header3); } } transportMailItem.RootPart.Headers.RemoveAll("X-MS-Exchange-Organization-OriginalArrivalTime"); transportMailItem.RootPart.Headers.AppendChild(new AsciiTextHeader("X-MS-Exchange-Organization-OriginalArrivalTime", Util.FormatOrganizationalMessageArrivalTime(utcNow))); transportMailItem.UpdateDirectionalityAndScopeHeaders(); transportMailItem.UpdateCachedHeaders(); MessageTrackingLog.TrackReceiveForApprovalRelease(transportMailItem, approverAddress, messageItem.InternetMessageId); return(true); }
public void TestHeaderParser() { var bytes = Encoding.ASCII.GetBytes("Header-1: value 1\r\nHeader-2: value 2\r\nHeader-3: value 3\r\n\r\n"); using (var memory = new MemoryStream(bytes, false)) { try { var headers = HeaderList.Load(memory); string value; Assert.AreEqual(3, headers.Count, "Unexpected header count."); value = headers["Header-1"]; Assert.AreEqual("value 1", value, "Unexpected header value."); value = headers["Header-2"]; Assert.AreEqual("value 2", value, "Unexpected header value."); value = headers["Header-3"]; Assert.AreEqual("value 3", value, "Unexpected header value."); } catch (Exception ex) { Assert.Fail("Failed to parse headers: {0}", ex); } } }
public void TestRemovingHeaders() { var headers = new HeaderList(); headers.Add("From", "sender@localhost"); headers.Add("To", "first@localhost"); headers.Add("To", "second@localhost"); headers.Add("To", "third@localhost"); headers.Add("To", "fourth@localhost"); headers.Add("Cc", "carbon.copy@localhost"); Assert.IsFalse(headers.IsReadOnly); Assert.IsFalse(headers.Contains(new Header(HeaderId.Received, "value"))); Assert.AreEqual(-1, headers.IndexOf(new Header(HeaderId.Received, "value"))); Assert.AreEqual(-1, headers.IndexOf("Received")); Assert.AreEqual(-1, headers.LastIndexOf(HeaderId.Received)); Assert.AreEqual(null, headers[HeaderId.Received]); Assert.IsTrue(headers.Remove("Cc")); // try removing a header that no longer exists Assert.IsFalse(headers.Remove(new Header(HeaderId.Cc, "value"))); Assert.IsFalse(headers.Remove(HeaderId.Cc)); Assert.IsFalse(headers.Remove("Cc")); // removing this will change the result of headers[HeaderId.To] Assert.AreEqual("first@localhost", headers[HeaderId.To]); Assert.IsTrue(headers.Remove(HeaderId.To)); Assert.AreEqual("second@localhost", headers[HeaderId.To]); Assert.IsTrue(headers.Remove("To")); Assert.AreEqual("third@localhost", headers[HeaderId.To]); headers.RemoveAt(headers.IndexOf("To")); Assert.AreEqual("fourth@localhost", headers[HeaderId.To]); }
/// <summary> /// Evaluates the node, using the variables provided in the <paramref name="Variables"/> collection. /// </summary> /// <param name="Arguments">Function arguments.</param> /// <param name="Variables">Variables collection.</param> /// <returns>Result.</returns> public override IElement Evaluate(IElement[] Arguments, Variables Variables) { Uri Url = new Uri(Arguments[0].AssociatedObjectValue?.ToString()); List <KeyValuePair <string, string> > HeaderList = null; if (Arguments.Length > 1) { object Arg1 = Arguments[1].AssociatedObjectValue; if (Arg1 is IDictionary <string, IElement> Headers) { HeaderList = new List <KeyValuePair <string, string> >(); foreach (KeyValuePair <string, IElement> P in Headers) { HeaderList.Add(new KeyValuePair <string, string>(P.Key, P.Value.AssociatedObjectValue?.ToString())); } } else if (Arg1 is string Accept) { HeaderList = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("Accept", Accept) }; } else { throw new ScriptRuntimeException("Invalid second parameter to Get. Should be either an accept string, or an object with protocol-specific headers or options.", this); } } object Result = InternetContent.GetAsync(Url, HeaderList?.ToArray() ?? new KeyValuePair <string, string> [0]).Result; return(new ObjectValue(Result)); }
internal static void SetProperty(HeaderList mimeHeaders, string name, string value) { mimeHeaders.RemoveAll(name); if (!string.IsNullOrEmpty(value)) { mimeHeaders.AppendChild(new TextHeader(name, value)); } }
private void Initialize(HttpMethod method) { Method = method; StatusLine.Clear(); HeaderList.Clear(); MessageBody = null; c = TextStore.ReadChar(); }
public static bool IsInitiationMessage(EmailMessage message) { HeaderList headers = message.MimeDocument.RootPart.Headers; Header header = headers.FindFirst("X-MS-Exchange-Organization-Approval-Initiator"); Header header2 = headers.FindFirst("X-MS-Exchange-Organization-Approval-Allowed-Decision-Makers"); return(header != null && header2 != null); }
public override byte[] GetHeader(params HttpHeader[] rewrites) { sb.Clear(); sb.Append(StatusLine.ToString()); HeaderList.Format(sb, rewrites); sb.Append("\r\n"); return(Encoding.GetBytes(sb.ToString())); }
public HeaderEnumerator (HeaderList headers) { if (headers == null) throw new ArgumentNullException ("headers"); iter = headers.GetIter (); this.headers = headers; }
private void AddUnparkedHeader(HeaderList headers, Guid messageId) { headers.RemoveAll("X-MS-Exchange-Calendar-Series-Instance-Unparked"); Header header = Header.Create("X-MS-Exchange-Calendar-Series-Instance-Unparked"); header.Value = messageId.ToString(); headers.AppendChild(header); }
public S3Response put(string bucket, string key, S3Content content, HeaderList headers) { WebRequest webRequest = this.BuildWebRequest("PUT", bucket + "/" + this.EncodeKeyForSignature(key), headers); webRequest.ContentLength = (long)content.Bytes.Length; Stream requestStream = webRequest.GetRequestStream(); requestStream.Write(content.Bytes, 0, content.Bytes.Length); requestStream.Close(); return S3Response.Execute(webRequest); }
private void SendApprovalRequest(ApprovalRequestWriter writer, ICollection <RoutingAddress> p1DecisionMakers, CultureInfo cultureInfo, string messageId, byte[] corelationBlob) { IList <RoutingAddress> decisionMakers = this.initiationMessage.DecisionMakers; byte[] conversationIndex = this.initiationMessageItem.ConversationIndex; (string)this.initiationMessage.Requestor; using (MessageItemApprovalRequest messageItemApprovalRequest = this.requestCreate(this.mbxTransportMailItem)) { messageItemApprovalRequest.SetSender(this.approvalRequestSender); foreach (RoutingAddress routingAddress in decisionMakers) { bool flag = p1DecisionMakers == null || p1DecisionMakers.Contains(routingAddress); messageItemApprovalRequest.AddRecipient(routingAddress, flag); InitiationProcessor.diag.TraceDebug <RoutingAddress, bool>(0L, "Added recipient '{0}' with promote to P1={1}.", routingAddress, flag); } CultureInfo cultureInfo2; if (!writer.WriteSubjectAndBody(messageItemApprovalRequest, cultureInfo, out cultureInfo2)) { InitiationProcessor.diag.TraceError <ApprovalRequestWriter>(0L, "Approval request body cannot be written with writer {0}", writer); } messageItemApprovalRequest.ApprovalRequestor = this.initiationMessage.Requestor; messageItemApprovalRequest.MessageItem[ItemSchema.NormalizedSubject] = this.initiationMessageItem.ConversationTopic; messageItemApprovalRequest.MessageItem.Importance = this.initiationMessageItem.Importance; messageItemApprovalRequest.MessageItem.References = InitiationProcessor.ConstructApprovalRequestReferences(this.initiationMessageItem); ConversationIndex o = ConversationIndex.CreateFromParent(conversationIndex); if (!ConversationIndex.Empty.Equals(o)) { messageItemApprovalRequest.MessageItem.ConversationIndex = o.ToByteArray(); } if (cultureInfo2 != null) { InitiationProcessor.diag.TraceDebug <CultureInfo>(0L, "Approval request written in {0}", cultureInfo2); messageItemApprovalRequest.MessageItem[MessageItemSchema.MessageLocaleId] = cultureInfo2.LCID; } foreach (Attachment attachment in this.initiationMessage.EmailMessage.Attachments) { messageItemApprovalRequest.AddAttachment(attachment, this.mbxTransportMailItem.ADRecipientCache.ADSession); } if (this.initiationMessage.EmailMessage.RootPart != null && this.initiationMessage.EmailMessage.RootPart.Headers != null) { HeaderList headers = this.initiationMessage.EmailMessage.RootPart.Headers; Header[] array = headers.FindAll("X-MS-Exchange-Inbox-Rules-Loop"); if (array != null && array.Length > 0) { string[] array2 = new string[array.Length]; for (int i = 0; i < array.Length; i++) { array2[i] = array[i].Value; } messageItemApprovalRequest.MessageItem.SafeSetProperty(MessageItemSchema.XLoop, array2); } } InitiationProcessor.AddVotingToApprovalRequest(messageItemApprovalRequest, this.initiationMessage.VotingActions, cultureInfo2); messageItemApprovalRequest.Send(messageId, corelationBlob, this.mbxTransportMailItem); } }
public bool IsHeaderExist(string Name, bool throwException = true) { bool exist = HeaderList.Any(x => x.Name == Name); if (exist && throwException) { throw new HttpHandlerExceptiosn($"Global Param: {Name} is already declared", "Encabezados", ExceptionError.Internal_InconsistencyData); } return(exist); }
public void RemoveParameter(string ParameterName) { if (!IsHeaderExist(ParameterName, false)) { throw new HttpHandlerExceptiosn($"Parameter : {ParameterName} not found", "Encabezados", ExceptionError.Internal_InconsistencyData); } var removeItem = HeaderList.First(x => x.Name == ParameterName); HeaderList.Remove(removeItem); }
internal static string GetProperty(HeaderList mimeHeaders, string name) { Header header = mimeHeaders.FindFirst(name); if (header == null || header.Value == null) { return(null); } return(header.Value); }
public HeaderEnumerator(HeaderList headers) { if (headers == null) { throw new ArgumentNullException("headers"); } iter = headers.GetIter(); this.headers = headers; }
protected override void Execute(CodeActivityContext context) { var csvPath = CSVPath.Get(context); var isHeader = IsHeader.Get(context); char delimeter = Delimeter.Get(context); List <string> headerList = HeaderList.Get(context); CSVToDataTableConverter converter = new CSVToDataTableConverter(csvPath, isHeader, headerList, delimeter); ResultListItems.Set(context, converter.getDataTableCSVFile()); }
private void decompress_Mode(byte[] buffer, byte mode, ushort windowSize) { CircularBuffer circularBuffer = new CircularBuffer(windowSize); string outputPath = FilePath + ".OUT"; using (BinaryWriter writer = new BinaryWriter(new FileStream(outputPath, FileMode.Create))) { writer.Write(buffer, 0, 1); circularBuffer.AddData(new byte[] { buffer[0] }); for (int i = 1; i < buffer.Length; i++) { bool[] flags = GetFlags(buffer[i]); for (int j = 7; j >= 0; j--) { if (flags[j]) { byte[] wordBytes = new byte[2]; Array.Copy(buffer, ++i, wordBytes, 0, 2); CompressedWord word = new CompressedWord(wordBytes, mode); byte[] result = circularBuffer.GetData(word.Offset, word.Length); i++; writer.Write(result, 0, result.Length); } else { if (i < buffer.Length - 1) { writer.Write(buffer, ++i, 1); circularBuffer.AddData(new byte[] { buffer[i] }); } } if (writer.BaseStream.Length >= LZSSHeader.UncompressedSize) { break; } } if (writer.BaseStream.Length >= LZSSHeader.UncompressedSize) { break; } } } DecompressedFile = HeaderList.GetTypeFromFile(outputPath); string headerPath = Path.Combine(Path.GetDirectoryName(FilePath), Path.GetFileName(FilePath) + ".HEADER"); using (BinaryWriter writer = new BinaryWriter(new FileStream(headerPath, FileMode.Create))) { writer.Write(LZSSHeader.GetBytes()); } HeaderFile = new BaseFile(headerPath); }
public void CanAddCustomerHeader() { // Arrange Request request = Session.Request(HeaderListUrl); // Act HeaderList headers = request.Header("X-Ramone", "123").Get <HeaderList>().Body; // Assert Assert.IsTrue(headers.Any(h => h == "X-Ramone: 123"), "Must contain customer header"); }
private static Guid GetAddressBookPolicy(HeaderList headers) { ArgumentValidator.ThrowIfNull("headers", headers); Header header = headers.FindFirst("X-MS-Exchange-ABP-GUID"); if (header != null) { return(StoreDriverDelivery.GetHeaderValueAsGuid(header)); } return(Guid.Empty); }
private static Guid GetGal(HeaderList headers) { ArgumentValidator.ThrowIfNull("headers", headers); Header header = headers.FindFirst("X-MS-Exchange-Forest-GAL-Scope"); if (header != null) { return(StoreDriverDelivery.GetHeaderValueAsGuid(header)); } return(Guid.Empty); }
private void CacheInstanceId(HeaderList headers, StoreId instanceCalendarItemId) { Header header = headers.FindFirst("X-MS-Exchange-Calendar-Series-Instance-Calendar-Item-Id"); if (header == null) { header = Header.Create("X-MS-Exchange-Calendar-Series-Instance-Calendar-Item-Id"); headers.AppendChild(header); } header.Value = StoreId.GetStoreObjectId(instanceCalendarItemId).ToBase64String(); }
/// <summary> /// Creates an empty mail merge message. /// </summary> public MailMergeMessage() { Config.IgnoreIllegalRecipientAddresses = true; Config.Priority = MessagePriority.Normal; Headers = new HeaderList(); Subject = string.Empty; SmartFormatter = new MailSmartFormatter(this); // Smart.Format("{Name:choose(null|):N/A|empty|{Name}}", variable), where abc.Name NULL, string.Emtpy or a string MailMergeAddresses = new MailMergeAddressCollection(this); }
public object Get() { HeaderList list = new HeaderList(); NameValueCollection headers = HttpContext.Current.Request.Headers; foreach (string header in headers.AllKeys) { list.Add(string.Format("{0}: {1}", header, headers[header])); } return list; }
public object Get() { HeaderList list = new HeaderList(); NameValueCollection headers = HttpContext.Current.Request.Headers; foreach (string header in headers.AllKeys) { list.Add(string.Format("{0}: {1}", header, headers[header])); } return(list); }
internal static bool TryGetFromHeader(HeaderList mimeHeader, out EmailMessageHash result) { result = null; string property = XHeaderUtils.GetProperty(mimeHeader, "X-MS-Exchange-Forest-EmailMessageHash"); if (string.IsNullOrEmpty(property)) { return(false); } result = new EmailMessageHash(property); return(true); }
internal static string GetMessageId(this HeaderList headerCollection) { var messageIdHeaderEntry = headerCollection["Message-ID"]; if (string.IsNullOrEmpty(messageIdHeaderEntry)) { messageIdHeaderEntry = headerCollection.ToHMSGID(); return(messageIdHeaderEntry); } return(messageIdHeaderEntry); }
private static void AddExchangeOrganizationBccHeader(List <MimeRecipient> bccRecipientList, TransportMailItem mailItem) { AddressHeader addressHeader = new AddressHeader("X-MS-Exchange-Organization-BCC"); foreach (MimeRecipient newChild in bccRecipientList) { addressHeader.AppendChild(newChild); } HeaderList headers = mailItem.Message.MimeDocument.RootPart.Headers; headers.AppendChild(addressHeader); }
public void TestSerializedContent() { const string expected = "Reporting-MTA: dns; mm1\nArrival-Date: Mon, 29 Jul 1996 02:12:50 -0700\n\nFinal-Recipient: RFC822; [email protected]\nAction: failed\nDiagnostic-Code: X-LOCAL; 500 (err.nosuchuser)\n\n"; var mds = new MessageDeliveryStatus(); var recipient = new HeaderList(); var status = new HeaderList(); status.Add("Reporting-MTA", "dns; mm1"); status.Add("Arrival-Date", DateUtils.FormatDate(new DateTimeOffset(1996, 7, 29, 2, 12, 50, new TimeSpan(-7, 0, 0)))); recipient.Add("Final-Recipient", "RFC822; [email protected]"); recipient.Add("Action", "failed"); recipient.Add("Diagnostic-Code", "X-LOCAL; 500 (err.nosuchuser)"); mds.StatusGroups.Add(status); mds.StatusGroups.Add(recipient); Assert.IsTrue(mds.StatusGroups.Contains(status), "Expected the groups to contain the per-message status group."); Assert.IsTrue(mds.StatusGroups.Contains(recipient), "Expected the groups to contain the recipient status group."); Assert.IsFalse(mds.StatusGroups.IsReadOnly, "The status groups should not be read-only."); using (var memory = new MemoryStream()) { mds.ContentObject.DecodeTo(memory); var text = Encoding.ASCII.GetString(memory.GetBuffer(), 0, (int)memory.Length).Replace("\r\n", "\n"); Assert.AreEqual(expected, text); } var dummy = new HeaderList(); dummy.Add("Dummy-Header", "dummy value"); mds.StatusGroups.Add(dummy); Assert.IsTrue(mds.StatusGroups.Contains(dummy), "Expected the groups to contain the dummy group."); Assert.IsTrue(mds.StatusGroups.Remove(dummy), "Expected removal of the dummy group to be successful."); var expectedContent = mds.ContentObject; dummy.Add("Bogus-Header", "bogus value"); Assert.AreEqual(expectedContent, mds.ContentObject, "The content should not have changed since the dummy group has been removed."); mds.StatusGroups.Clear(); using (var memory = new MemoryStream()) { mds.ContentObject.DecodeTo(memory); var text = Encoding.ASCII.GetString(memory.GetBuffer(), 0, (int)memory.Length).Replace("\r\n", "\n"); Assert.AreEqual(string.Empty, text); } }
public void TestSerializedContent () { const string expected = "Reporting-MTA: dns; mm1\nArrival-Date: Mon, 29 Jul 1996 02:12:50 -0700\n\nFinal-Recipient: RFC822; [email protected]\nAction: failed\nDiagnostic-Code: X-LOCAL; 500 (err.nosuchuser)\n\n"; var mds = new MessageDeliveryStatus (); var recipient = new HeaderList (); var status = new HeaderList (); status.Add ("Reporting-MTA", "dns; mm1"); status.Add ("Arrival-Date", DateUtils.FormatDate (new DateTimeOffset (1996, 7, 29, 2, 12, 50, new TimeSpan (-7, 0, 0)))); recipient.Add ("Final-Recipient", "RFC822; [email protected]"); recipient.Add ("Action", "failed"); recipient.Add ("Diagnostic-Code", "X-LOCAL; 500 (err.nosuchuser)"); mds.StatusGroups.Add (status); mds.StatusGroups.Add (recipient); Assert.IsTrue (mds.StatusGroups.Contains (status), "Expected the groups to contain the per-message status group."); Assert.IsTrue (mds.StatusGroups.Contains (recipient), "Expected the groups to contain the recipient status group."); Assert.IsFalse (mds.StatusGroups.IsReadOnly, "The status groups should not be read-only."); using (var memory = new MemoryStream ()) { mds.ContentObject.DecodeTo (memory); var text = Encoding.ASCII.GetString (memory.GetBuffer (), 0, (int) memory.Length).Replace ("\r\n", "\n"); Assert.AreEqual (expected, text); } var dummy = new HeaderList (); dummy.Add ("Dummy-Header", "dummy value"); mds.StatusGroups.Add (dummy); Assert.IsTrue (mds.StatusGroups.Contains (dummy), "Expected the groups to contain the dummy group."); Assert.IsTrue (mds.StatusGroups.Remove (dummy), "Expected removal of the dummy group to be successful."); var expectedContent = mds.ContentObject; dummy.Add ("Bogus-Header", "bogus value"); Assert.AreEqual (expectedContent, mds.ContentObject, "The content should not have changed since the dummy group has been removed."); mds.StatusGroups.Clear (); using (var memory = new MemoryStream ()) { mds.ContentObject.DecodeTo (memory); var text = Encoding.ASCII.GetString (memory.GetBuffer (), 0, (int) memory.Length).Replace ("\r\n", "\n"); Assert.AreEqual (string.Empty, text); } }
public void TestReplacingHeaders() { const string ReplacedContentType = "text/plain; charset=iso-8859-1; name=body.txt"; const string ReplacedContentDisposition = "inline; filename=body.txt"; const string ReplacedContentLocation = "http://www.example.com/location"; const string ReplacedContentId = "<content.id.2@localhost>"; var headers = new HeaderList(); headers.Add(HeaderId.ContentId, "<content-id.1@localhost>"); headers.Add("Content-Location", "http://www.location.com"); headers.Insert(0, HeaderId.ContentDisposition, "attachment"); headers.Insert(0, "Content-Type", "text/plain"); Assert.IsTrue(headers.Contains(HeaderId.ContentType), "Expected the list of headers to contain HeaderId.ContentType."); Assert.IsTrue(headers.Contains("Content-Type"), "Expected the list of headers to contain a Content-Type header."); Assert.AreEqual(0, headers.LastIndexOf(HeaderId.ContentType), "Expected the Content-Type header to be the first header."); headers.Replace("Content-Disposition", ReplacedContentDisposition); Assert.AreEqual(4, headers.Count, "Unexpected number of headers after replacing Content-Disposition."); Assert.AreEqual(ReplacedContentDisposition, headers["Content-Disposition"], "Content-Disposition has unexpected value after replacing it."); Assert.AreEqual(1, headers.IndexOf("Content-Disposition"), "Replaced Content-Disposition not in the expected position."); headers.Replace(HeaderId.ContentType, ReplacedContentType); Assert.AreEqual(4, headers.Count, "Unexpected number of headers after replacing Content-Type."); Assert.AreEqual(ReplacedContentType, headers["Content-Type"], "Content-Type has unexpected value after replacing it."); Assert.AreEqual(0, headers.IndexOf("Content-Type"), "Replaced Content-Type not in the expected position."); headers.Replace(HeaderId.ContentId, Encoding.UTF8, ReplacedContentId); Assert.AreEqual(4, headers.Count, "Unexpected number of headers after replacing Content-Id."); Assert.AreEqual(ReplacedContentId, headers["Content-Id"], "Content-Id has unexpected value after replacing it."); Assert.AreEqual(2, headers.IndexOf("Content-Id"), "Replaced Content-Id not in the expected position."); headers.Replace("Content-Location", Encoding.UTF8, ReplacedContentLocation); Assert.AreEqual(4, headers.Count, "Unexpected number of headers after replacing Content-Location."); Assert.AreEqual(ReplacedContentLocation, headers["Content-Location"], "Content-Location has unexpected value after replacing it."); Assert.AreEqual(3, headers.IndexOf("Content-Location"), "Replaced Content-Location not in the expected position."); headers.RemoveAll("Content-Location"); Assert.AreEqual(3, headers.Count, "Unexpected number of headers after removing Content-Location."); headers.Clear(); headers.Add(HeaderId.Received, "received 1"); headers.Add(HeaderId.Received, "received 2"); headers.Add(HeaderId.Received, "received 3"); headers.Add(HeaderId.ReturnPath, "return-path"); headers[0] = new Header(HeaderId.ReturnPath, "new return-path"); Assert.AreEqual("new return-path", headers[HeaderId.ReturnPath]); headers[0] = new Header(HeaderId.Received, "new received"); Assert.AreEqual("new received", headers[HeaderId.Received]); }
public void WhenSendingRequestItPassesUserAgent() { // Arrange Session.UserAgent = "AgentTest/007"; Request req = Session.Request(HeaderListUrl); // Act HeaderList headers = req.Get <HeaderList>().Body; // Assert Assert.IsNotNull(headers); Assert.IsTrue(headers.Exists(h => h == "User-Agent: AgentTest/007")); }
public void CanSetTypedAcceptHeaderWithQValueFromString() { // Act var request = AcceptSession.Bind(HeaderListUrl).Accept <HeaderList>("application/xml", 0.34); using (var r = request.Get()) { HeaderList headers = r.Body; // Assert Assert.IsTrue(headers.Any(h => h == "Accept: application/xml; q=0.34"), "Must contain Accept header with q-value"); } }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.MimeEntity"/> class /// based on the <see cref="MimeEntityConstructorInfo"/>. /// </summary> /// <remarks> /// Custom <see cref="MimeEntity"/> subclasses MUST implement this constructor /// in order to register it using <see cref="ParserOptions.RegisterMimeType"/>. /// </remarks> /// <param name="entity">Information used by the constructor.</param> protected MimeEntity (MimeEntityConstructorInfo entity) { if (entity == null) throw new ArgumentNullException ("entity"); Headers = new HeaderList (entity.ParserOptions); ContentType = entity.ContentType; ContentType.Changed += ContentTypeChanged; Headers.Changed += HeadersChanged; foreach (var header in entity.Headers) { if (entity.IsTopLevel && !header.Field.StartsWith ("Content-", StringComparison.OrdinalIgnoreCase)) continue; Headers.Add (header); } }
public void TestReplacingMultipleHeaders () { const string CombinedRecpients = "first@localhost, second@localhost, third@localhost"; var headers = new HeaderList (); headers.Add ("From", "sender@localhost"); headers.Add ("To", "first@localhost"); headers.Add ("To", "second@localhost"); headers.Add ("To", "third@localhost"); headers.Add ("Cc", "carbon.copy@localhost"); headers.Replace ("To", CombinedRecpients); Assert.AreEqual (3, headers.Count, "Unexpected number of headers after replacing To header."); Assert.AreEqual (CombinedRecpients, headers["To"], "To header has unexpected value after being replaced."); Assert.AreEqual (1, headers.IndexOf ("To"), "Replaced To header not in the expected position."); Assert.AreEqual (0, headers.IndexOf ("From"), "From header not in the expected position."); Assert.AreEqual (2, headers.IndexOf ("Cc"), "Cc header not in the expected position."); }
public void SetHeaders(HeaderList AHeaders) { string S = ""; if (_Authentication != null) { S = _Authentication.Authentication(); if (S.Length > 0) { AHeaders.Values("Proxy-Authentication", S); } } else { if (_BasicByDefault) { _Authentication = new BasicAuthentication(); _Authentication.UserName = _UserName; _Authentication.Password = _Password; S = _Authentication.Authentication(); if (S.Length > 0) { AHeaders.Values("Proxy-Authentication", S); } } } }
public void TestReplacingHeaders () { const string ReplacedContentType = "text/plain; charset=iso-8859-1; name=body.txt"; const string ReplacedContentDisposition = "inline; filename=body.txt"; const string ReplacedContentLocation = "http://www.example.com/location"; const string ReplacedContentId = "<content.id.2@localhost>"; var headers = new HeaderList (); headers.Add (HeaderId.ContentId, "<content-id.1@localhost>"); headers.Add ("Content-Location", "http://www.location.com"); headers.Insert (0, HeaderId.ContentDisposition, "attachment"); headers.Insert (0, "Content-Type", "text/plain"); Assert.IsTrue (headers.Contains (HeaderId.ContentType), "Expected the list of headers to contain HeaderId.ContentType."); Assert.IsTrue (headers.Contains ("Content-Type"), "Expected the list of headers to contain a Content-Type header."); Assert.AreEqual (0, headers.LastIndexOf (HeaderId.ContentType), "Expected the Content-Type header to be the first header."); headers.Replace ("Content-Disposition", ReplacedContentDisposition); Assert.AreEqual (4, headers.Count, "Unexpected number of headers after replacing Content-Disposition."); Assert.AreEqual (ReplacedContentDisposition, headers["Content-Disposition"], "Content-Disposition has unexpected value after replacing it."); Assert.AreEqual (1, headers.IndexOf ("Content-Disposition"), "Replaced Content-Disposition not in the expected position."); headers.Replace (HeaderId.ContentType, ReplacedContentType); Assert.AreEqual (4, headers.Count, "Unexpected number of headers after replacing Content-Type."); Assert.AreEqual (ReplacedContentType, headers["Content-Type"], "Content-Type has unexpected value after replacing it."); Assert.AreEqual (0, headers.IndexOf ("Content-Type"), "Replaced Content-Type not in the expected position."); headers.Replace (HeaderId.ContentId, Encoding.UTF8, ReplacedContentId); Assert.AreEqual (4, headers.Count, "Unexpected number of headers after replacing Content-Id."); Assert.AreEqual (ReplacedContentId, headers["Content-Id"], "Content-Id has unexpected value after replacing it."); Assert.AreEqual (2, headers.IndexOf ("Content-Id"), "Replaced Content-Id not in the expected position."); headers.Replace ("Content-Location", Encoding.UTF8, ReplacedContentLocation); Assert.AreEqual (4, headers.Count, "Unexpected number of headers after replacing Content-Location."); Assert.AreEqual (ReplacedContentLocation, headers["Content-Location"], "Content-Location has unexpected value after replacing it."); Assert.AreEqual (3, headers.IndexOf ("Content-Location"), "Replaced Content-Location not in the expected position."); headers.RemoveAll ("Content-Location"); Assert.AreEqual (3, headers.Count, "Unexpected number of headers after removing Content-Location."); }
/// <summary> /// Init components. /// </summary> private void _initializeComponents() { VBox MainContent = new VBox() { Margin = 0 }; // Info window InfoBox MainInfoBox = new InfoBox(Director.Properties.Resources.DefaultServerHeaders, DirectorImages.SETTINGS_IMAGE); MainContent.PackStart(MainInfoBox); // Add header list HeaderControl = new HeaderList(ActiveServer.DefaultHeaders) { BackgroundColor = Colors.White }; MainContent.PackStart(HeaderControl, expand: true, fill: true); // Close button Buttons.Add(new DialogButton(Director.Properties.Resources.Confirm, Command.Ok)); // Set content Content = MainContent; }
public Stream ReadFile(string relativePath) { string path = this.GetPath(relativePath); HeaderList headers = new HeaderList(); return this.s3adaptor.getStream(this.bucketName, path, headers); }
public EntityHeaderInfo() { _CustomHeaders = new HeaderList(); _RawHeaders = new HeaderList(); _RawHeaders.FoldLength = 1024; Clear(); }
/// <summary> /// Get the headers of the messages within the specified range. /// </summary> /// <remarks> /// Gets the headers of the messages within the specified range. /// </remarks> /// <returns>The headers of the messages within the specified range.</returns> /// <param name="startIndex">The index of the first message to get.</param> /// <param name="count">The number of messages to get.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <exception cref="System.ArgumentOutOfRangeException"> /// <paramref name="startIndex"/> and <paramref name="count"/> do not specify /// a valid range of messages. /// </exception> /// <exception cref="System.ObjectDisposedException"> /// The <see cref="Pop3Client"/> has been disposed. /// </exception> /// <exception cref="InvalidOperationException"> /// The <see cref="Pop3Client"/> is not connected. /// </exception> /// <exception cref="System.UnauthorizedAccessException"> /// The <see cref="Pop3Client"/> is not authenticated. /// </exception> /// <exception cref="System.NotSupportedException"> /// The POP3 server does not support the UIDL extension. /// </exception> /// <exception cref="System.OperationCanceledException"> /// The operation was canceled via the cancellation token. /// </exception> /// <exception cref="System.IO.IOException"> /// An I/O error occurred. /// </exception> /// <exception cref="Pop3CommandException"> /// The POP3 command failed. /// </exception> /// <exception cref="Pop3ProtocolException"> /// A POP3 protocol error occurred. /// </exception> public override IList<HeaderList> GetMessageHeaders(int startIndex, int count, CancellationToken cancellationToken = default (CancellationToken)) { if (startIndex < 0 || startIndex >= total) throw new ArgumentOutOfRangeException ("startIndex"); if (count < 0 || count > (total - startIndex)) throw new ArgumentOutOfRangeException ("count"); CheckDisposed (); CheckConnected (); if (engine.State != Pop3EngineState.Transaction) throw new UnauthorizedAccessException (); if (count == 0) return new HeaderList[0]; var seqids = new int[count]; for (int i = 0; i < count; i++) seqids[i] = startIndex + i + 1; var messages = GetMessagesForSequenceIds (seqids, true, cancellationToken); var headers = new HeaderList[messages.Count]; for (int i = 0; i < headers.Length; i++) headers[i] = messages[i].Headers; return headers; }
/// <summary> /// Get the headers for the specified messages. /// </summary> /// <remarks> /// Gets the headers for the specified messages. /// </remarks> /// <returns>The headers for the specified messages.</returns> /// <param name="uids">The UIDs of the messages.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="uids"/> is <c>null</c>. /// </exception> /// <exception cref="System.ArgumentException"> /// <para>One or more of the <paramref name="uids"/> are invalid.</para> /// <para>-or-</para> /// <para>No uids were specified.</para> /// </exception> /// <exception cref="System.ObjectDisposedException"> /// The <see cref="Pop3Client"/> has been disposed. /// </exception> /// <exception cref="InvalidOperationException"> /// The <see cref="Pop3Client"/> is not connected. /// </exception> /// <exception cref="System.UnauthorizedAccessException"> /// The <see cref="Pop3Client"/> is not authenticated. /// </exception> /// <exception cref="System.NotSupportedException"> /// The POP3 server does not support the UIDL extension. /// </exception> /// <exception cref="System.OperationCanceledException"> /// The operation was canceled via the cancellation token. /// </exception> /// <exception cref="System.IO.IOException"> /// An I/O error occurred. /// </exception> /// <exception cref="Pop3CommandException"> /// The POP3 command failed. /// </exception> /// <exception cref="Pop3ProtocolException"> /// A POP3 protocol error occurred. /// </exception> public override IList<HeaderList> GetMessageHeaders(IList<string> uids, CancellationToken cancellationToken = default (CancellationToken)) { if (uids == null) throw new ArgumentNullException ("uids"); if (uids.Count == 0) throw new ArgumentException ("No uids specified.", "uids"); CheckDisposed (); CheckConnected (); if (engine.State != Pop3EngineState.Transaction) throw new UnauthorizedAccessException (); var seqids = new int[uids.Count]; for (int i = 0; i < uids.Count; i++) { int seqid; if (!dict.TryGetValue (uids[i], out seqid)) throw new ArgumentException ("One or more of the uids is invalid.", "uids"); seqids[i] = seqid; } var messages = GetMessagesForSequenceIds (seqids, true, cancellationToken); var headers = new HeaderList[messages.Count]; for (int i = 0; i < headers.Length; i++) headers[i] = messages[i].Headers; return headers; }
public void TestArgumentExceptions () { var list = new HeaderList (); Header header; string value; // Add Assert.Throws<ArgumentNullException> (() => list.Add (null)); Assert.Throws<ArgumentOutOfRangeException> (() => list.Add (HeaderId.Unknown, "value")); Assert.Throws<ArgumentNullException> (() => list.Add (HeaderId.AdHoc, null)); Assert.Throws<ArgumentNullException> (() => list.Add (null, "value")); Assert.Throws<ArgumentNullException> (() => list.Add ("field", null)); Assert.Throws<ArgumentOutOfRangeException> (() => list.Add (HeaderId.Unknown, Encoding.UTF8, "value")); Assert.Throws<ArgumentNullException> (() => list.Add (HeaderId.AdHoc, null, "value")); Assert.Throws<ArgumentNullException> (() => list.Add (HeaderId.AdHoc, Encoding.UTF8, null)); Assert.Throws<ArgumentNullException> (() => list.Add (null, Encoding.UTF8, "value")); Assert.Throws<ArgumentNullException> (() => list.Add ("field", null, "value")); Assert.Throws<ArgumentNullException> (() => list.Add ("field", Encoding.UTF8, null)); // Contains Assert.Throws<ArgumentOutOfRangeException> (() => list.Contains (HeaderId.Unknown)); Assert.Throws<ArgumentNullException> (() => list.Contains ((Header) null)); Assert.Throws<ArgumentNullException> (() => list.Contains ((string) null)); // CopyTo Assert.Throws<ArgumentOutOfRangeException> (() => list.CopyTo (new Header[0], -1)); Assert.Throws<ArgumentNullException> (() => list.CopyTo (null, 0)); // IndexOf Assert.Throws<ArgumentOutOfRangeException> (() => list.IndexOf (HeaderId.Unknown)); Assert.Throws<ArgumentNullException> (() => list.IndexOf ((Header) null)); Assert.Throws<ArgumentNullException> (() => list.IndexOf ((string) null)); // Insert list.Add ("field", "value"); Assert.Throws<ArgumentOutOfRangeException> (() => list.Insert (-1, new Header (HeaderId.AdHoc, "value"))); Assert.Throws<ArgumentOutOfRangeException> (() => list.Insert (-1, HeaderId.AdHoc, Encoding.UTF8, "value")); Assert.Throws<ArgumentOutOfRangeException> (() => list.Insert (-1, "field", Encoding.UTF8, "value")); Assert.Throws<ArgumentOutOfRangeException> (() => list.Insert (-1, HeaderId.AdHoc, "value")); Assert.Throws<ArgumentOutOfRangeException> (() => list.Insert (-1, "field", "value")); Assert.Throws<ArgumentOutOfRangeException> (() => list.Insert (0, HeaderId.Unknown, Encoding.UTF8, "value")); Assert.Throws<ArgumentOutOfRangeException> (() => list.Insert (0, HeaderId.Unknown, "value")); Assert.Throws<ArgumentNullException> (() => list.Insert (0, HeaderId.AdHoc, Encoding.UTF8, null)); Assert.Throws<ArgumentNullException> (() => list.Insert (0, HeaderId.AdHoc, null, "value")); Assert.Throws<ArgumentNullException> (() => list.Insert (0, HeaderId.AdHoc, null)); Assert.Throws<ArgumentNullException> (() => list.Insert (0, null, "value")); Assert.Throws<ArgumentNullException> (() => list.Insert (0, "field", null)); Assert.Throws<ArgumentNullException> (() => list.Insert (0, null)); // LastIndexOf Assert.Throws<ArgumentOutOfRangeException> (() => list.LastIndexOf (HeaderId.Unknown)); Assert.Throws<ArgumentNullException> (() => list.LastIndexOf ((string) null)); // Remove Assert.Throws<ArgumentOutOfRangeException> (() => list.Remove (HeaderId.Unknown)); Assert.Throws<ArgumentNullException> (() => list.Remove ((Header) null)); Assert.Throws<ArgumentNullException> (() => list.Remove ((string) null)); // RemoveAll Assert.Throws<ArgumentOutOfRangeException> (() => list.RemoveAll (HeaderId.Unknown)); Assert.Throws<ArgumentNullException> (() => list.RemoveAll ((string) null)); // RemoveAt Assert.Throws<ArgumentOutOfRangeException> (() => list.RemoveAt (-1)); // Replace Assert.Throws<ArgumentNullException> (() => list.Replace (null)); Assert.Throws<ArgumentOutOfRangeException> (() => list.Replace (HeaderId.Unknown, "value")); Assert.Throws<ArgumentNullException> (() => list.Replace (HeaderId.AdHoc, null)); Assert.Throws<ArgumentNullException> (() => list.Replace (null, "value")); Assert.Throws<ArgumentNullException> (() => list.Replace ("field", null)); Assert.Throws<ArgumentOutOfRangeException> (() => list.Replace (HeaderId.Unknown, Encoding.UTF8, "value")); Assert.Throws<ArgumentNullException> (() => list.Replace (HeaderId.AdHoc, null, "value")); Assert.Throws<ArgumentNullException> (() => list.Replace (HeaderId.AdHoc, Encoding.UTF8, null)); Assert.Throws<ArgumentNullException> (() => list.Replace (null, Encoding.UTF8, "value")); Assert.Throws<ArgumentNullException> (() => list.Replace ("field", null, "value")); Assert.Throws<ArgumentNullException> (() => list.Replace ("field", Encoding.UTF8, null)); using (var stream = new MemoryStream ()) { // Load Assert.Throws<ArgumentNullException> (() => HeaderList.Load (ParserOptions.Default, (Stream) null)); Assert.Throws<ArgumentNullException> (() => HeaderList.Load (ParserOptions.Default, (string) null)); Assert.Throws<ArgumentNullException> (() => HeaderList.Load (null, stream)); Assert.Throws<ArgumentNullException> (() => HeaderList.Load ((Stream) null)); Assert.Throws<ArgumentNullException> (() => HeaderList.Load ((string) null)); // WriteTo Assert.Throws<ArgumentNullException> (() => list.WriteTo (FormatOptions.Default, null)); Assert.Throws<ArgumentNullException> (() => list.WriteTo (null, stream)); Assert.Throws<ArgumentNullException> (() => list.WriteTo (null)); } // Indexers Assert.Throws<ArgumentOutOfRangeException> (() => list[-1] = new Header (HeaderId.AdHoc, "value")); Assert.Throws<ArgumentOutOfRangeException> (() => list[HeaderId.Unknown] = "value"); Assert.Throws<ArgumentOutOfRangeException> (() => value = list[HeaderId.Unknown]); Assert.Throws<ArgumentOutOfRangeException> (() => header = list[-1]); Assert.Throws<ArgumentNullException> (() => list[HeaderId.AdHoc] = null); Assert.Throws<ArgumentNullException> (() => value = list[null]); Assert.Throws<ArgumentNullException> (() => list[null] = "value"); Assert.Throws<ArgumentNullException> (() => list["field"] = null); Assert.Throws<ArgumentNullException> (() => list[0] = null); }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.MimeEntity"/> class. /// </summary> /// <remarks> /// Initializes the <see cref="ContentType"/> to the one provided. /// </remarks> /// <param name="contentType">The content type.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="contentType"/> is <c>null</c>. /// </exception> protected MimeEntity (ContentType contentType) { if (contentType == null) throw new ArgumentNullException ("contentType"); Headers = new HeaderList (); ContentType = contentType; ContentType.Changed += ContentTypeChanged; Headers.Changed += HeadersChanged; SerializeContentType (); }
public void TestRemovingHeaders () { var headers = new HeaderList (); headers.Add ("From", "sender@localhost"); headers.Add ("To", "first@localhost"); headers.Add ("To", "second@localhost"); headers.Add ("To", "third@localhost"); headers.Add ("Cc", "carbon.copy@localhost"); Assert.IsTrue (headers.Remove ("Cc")); // try removing a header that no longer exists Assert.IsFalse (headers.Remove (HeaderId.Cc)); Assert.IsFalse (headers.Remove ("Cc")); // removing this will change the result of headers[HeaderId.To] Assert.AreEqual ("first@localhost", headers[HeaderId.To]); Assert.IsTrue (headers.Remove (HeaderId.To)); Assert.AreEqual ("second@localhost", headers[HeaderId.To]); Assert.IsTrue (headers.Remove ("To")); Assert.AreEqual ("third@localhost", headers[HeaderId.To]); }
public ResponseHeaderInfo() { _ProxyAuthenticate = new HeaderList(); _WWWAuthenticate = new HeaderList(); }
private WebRequest BuildWebRequest(string method, string objectPath, HeaderList protoHeaders) { UriBuilder uriBuilder = new UriBuilder("http", "s3.amazonaws.com", 80, objectPath); WebRequest webRequest = WebRequest.Create(uriBuilder.ToString()); ((HttpWebRequest)webRequest).AllowWriteStreamBuffering = false; webRequest.Method = method; HeaderList headerList = new HeaderList(protoHeaders); headerList.AddHeaderIfAbsent("x-amz-date", DateTime.UtcNow.ToString("ddd, dd MMM yyyy HH:mm:ss ", CultureInfo.InvariantCulture) + "GMT"); for (int i = 0; i < headerList.Count; i++) { string a = headerList.Keys[i]; string contentType = headerList.Values[i]; if (a == "content-type") { webRequest.ContentType = contentType; } else { webRequest.Headers.Add(headerList.Keys[i], headerList.Values[i]); } } StringBuilder stringBuilder = new StringBuilder(); HeaderList headerList2 = new HeaderList(); foreach (string current in headerList.Keys) { string text = current.ToLower(); if (text == "content-type" || text == "content-md5" || text == "date" || text.StartsWith("x-amz-")) { headerList2.Add(text, headerList[current]); } } if (headerList2.ContainsKey("x-amz-date")) { headerList2["date"] = ""; } if (!headerList2.ContainsKey("content-type")) { headerList2["content-type"] = ""; } if (!headerList2.ContainsKey("content-md5")) { headerList2["content-md5"] = ""; } stringBuilder.Append(webRequest.Method); stringBuilder.Append("\n"); for (int j = 0; j < headerList2.Count; j++) { if (headerList2.Keys[j].StartsWith("x-amz-")) { stringBuilder.Append(headerList2.Keys[j]); stringBuilder.Append(":"); stringBuilder.Append(headerList2.Values[j].Trim()); } else { stringBuilder.Append(headerList2.Values[j]); } stringBuilder.Append("\n"); } stringBuilder.Append("/"); stringBuilder.Append(objectPath); string text2 = stringBuilder.ToString(); Encoding encoding = new UTF8Encoding(); HMACSHA1 hMACSHA = new HMACSHA1(encoding.GetBytes(this.secretAccessKey)); byte[] inArray = hMACSHA.ComputeHash(encoding.GetBytes(text2.ToCharArray())); string arg = Convert.ToBase64String(inArray); webRequest.Headers.Add("Authorization", string.Format("AWS {0}:{1}", this.accessKeyId, arg)); return webRequest; }
public void Dispose () { headers = null; iter = null; }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.MimeEntity"/> class. /// </summary> /// <param name="mediaType">The media type.</param> /// <param name="mediaSubtype">The media subtype.</param> /// <exception cref="System.ArgumentNullException"> /// <para><paramref name="mediaType"/> is <c>null</c>.</para> /// <para>-or-</para> /// <para><paramref name="mediaSubtype"/> is <c>null</c>.</para> /// </exception> protected MimeEntity(string mediaType, string mediaSubtype) { ContentType = new ContentType (mediaType, mediaSubtype); Headers = new HeaderList (); ContentType.Changed += ContentTypeChanged; Headers.Changed += HeadersChanged; SerializeContentType (); }
internal MimeMessage (ParserOptions options) { addresses = new Dictionary<string, InternetAddressList> (StringComparer.OrdinalIgnoreCase); Headers = new HeaderList (options); // initialize our address lists foreach (var name in StandardAddressHeaders) { var list = new InternetAddressList (); list.Changed += InternetAddressListChanged; addresses.Add (name, list); } references = new MessageIdList (); references.Changed += ReferencesChanged; inreplyto = null; Headers.Changed += HeadersChanged; }
protected void SetAuthParams(HeaderList AValue) { List<string> TempList = new List<string>(); AValue.ConvertToStdValues(TempList); _AuthParams.AddStdValues(TempList); }
/// <summary> /// Get the headers for the specified messages. /// </summary> /// <remarks> /// Gets the headers for the specified messages. /// </remarks> /// <returns>The headers for the specified messages.</returns> /// <param name="indexes">The indexes of the messages.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="indexes"/> is <c>null</c>. /// </exception> /// <exception cref="System.ArgumentException"> /// <para>One or more of the <paramref name="indexes"/> are invalid.</para> /// <para>-or-</para> /// <para>No indexes were specified.</para> /// </exception> /// <exception cref="System.ObjectDisposedException"> /// The <see cref="Pop3Client"/> has been disposed. /// </exception> /// <exception cref="InvalidOperationException"> /// The <see cref="Pop3Client"/> is not connected. /// </exception> /// <exception cref="System.UnauthorizedAccessException"> /// The <see cref="Pop3Client"/> is not authenticated. /// </exception> /// <exception cref="System.NotSupportedException"> /// The POP3 server does not support the UIDL extension. /// </exception> /// <exception cref="System.OperationCanceledException"> /// The operation was canceled via the cancellation token. /// </exception> /// <exception cref="System.IO.IOException"> /// An I/O error occurred. /// </exception> /// <exception cref="Pop3CommandException"> /// The POP3 command failed. /// </exception> /// <exception cref="Pop3ProtocolException"> /// A POP3 protocol error occurred. /// </exception> public override IList<HeaderList> GetMessageHeaders(IList<int> indexes, CancellationToken cancellationToken = default (CancellationToken)) { if (indexes == null) throw new ArgumentNullException ("indexes"); if (indexes.Count == 0) throw new ArgumentException ("No indexes specified.", "indexes"); CheckDisposed (); CheckConnected (); if (engine.State != Pop3EngineState.Transaction) throw new UnauthorizedAccessException (); var seqids = new int[indexes.Count]; for (int i = 0; i < indexes.Count; i++) { if (indexes[i] < 0 || indexes[i] >= total) throw new ArgumentException ("One or more of the indexes are invalid.", "indexes"); seqids[i] = indexes[i] + 1; } var messages = GetMessagesForSequenceIds (seqids, true, cancellationToken); var headers = new HeaderList[messages.Count]; for (int i = 0; i < headers.Length; i++) headers[i] = messages[i].Headers; return headers; }
public Stream getStream(string bucket, string key, HeaderList headers) { WebRequest webRequest = this.BuildWebRequest("GET", bucket + "/" + this.EncodeKeyForSignature(key), headers); WebResponse response = webRequest.GetResponse(); return response.GetResponseStream(); }