private void HeaderReceivedCallBack(IAsyncResult result)
        {
            ITransferContext context = (ITransferContext)result.AsyncState;
            int receive = context.Listener.EndReceive(result);

            if (receive > 0)
            {
                context.IncomingHeader(receive);
            }

            if (context.DeserialPacketSize > 0)
            {
                int buffersize = (context.DeserialPacketSize < context.BufferSize) ? (int)context.DeserialPacketSize : context.BufferSize;
                context.Listener.BeginReceive(context.HeaderBuffer, 0, buffersize, SocketFlags.None, HeaderReceivedCallBack, context);
            }
            else
            {
                TransferOperation request = new TransferOperation(context.Transfer, MessagePart.Header, DirectionType.Receive);
                request.Resolve(context.DeserialPacket);

                if (!context.ReceiveMessage &&
                    !context.SendMessage)
                {
                    context.Close = true;
                }

                context.HeaderReceivedNotice.Set();
                HeaderReceived.Execute(this);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The DealHeaderReceived.
        /// </summary>
        /// <param name="context">The context<see cref="ITransferContext"/>.</param>
        public void DealHeaderReceived(ITransferContext context)
        {
            if (context.BlockSize > 0)
            {
                int buffersize = (context.BlockSize < context.BufferSize) ? (int)context.BlockSize : context.BufferSize;
                context.Listener.BeginReceive(context.HeaderBuffer, 0, buffersize, SocketFlags.None, HeaderReceivedCallback, context);
            }
            else
            {
                TransferOperation request = new TransferOperation(context.Transfer, MessagePart.Header, DirectionType.Receive);
                request.Resolve(context);

                context.HeaderReceivedNotice.Set();

                try
                {
                    HeaderReceived.Execute(context);
                }
                catch (Exception ex)
                {
                    Echo(ex.Message);
                    CloseClient(context.Id);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// We've parsed a new header.
        /// </summary>
        /// <param name="name">Name in lower case</param>
        /// <param name="value">Value, unmodified.</param>
        /// <exception cref="BadRequestException">If content length cannot be parsed.</exception>
        protected void OnHeader(string name, string value)
        {
            m_headerArgs.Name  = name;
            m_headerArgs.Value = value;
            if (string.Compare(name, "content-length", true) == 0)
            {
                if (!int.TryParse(value, out m_bodyBytesLeft))
                {
                    throw new BadRequestException("Content length is not a number.");
                }
            }

            HeaderReceived?.Invoke(this, m_headerArgs);
        }
Esempio n. 4
0
        /// <summary>
        /// We've parsed a new header.
        /// </summary>
        /// <param name="name">Name in lower case</param>
        /// <param name="value">Value, unmodified.</param>
        /// <exception cref="BadRequestException">If content length cannot be parsed.</exception>
        protected void OnHeader()
        {
            if (string.Compare(m_curHeaderName, "content-length", true) == 0)
            {
                if (!int.TryParse(m_curHeaderValue, out m_bodyBytesLeft))
                {
                    throw new BadRequestException("Content length is not a number.");
                }
            }

            if (HeaderReceived != null)
            {
                m_headerArgs.Name  = m_curHeaderName;
                m_headerArgs.Value = m_curHeaderValue;
                HeaderReceived?.Invoke(this, m_headerArgs);
            }

            m_curHeaderName  = string.Empty;
            m_curHeaderValue = string.Empty;
        }
Esempio n. 5
0
 private static IDictionary<string, IHeaderFieldParser> CreateHeaderFieldList()
 {
     // NOTE: Header fields not mentioned here are treated as unstructured
       fieldMap = new Dictionary<string,
     IHeaderFieldParser>();
     fieldMap["content-return"] = new
     HeaderX400ContentReturn();
     fieldMap["x400-content-return"] = new HeaderX400ContentReturn();
     fieldMap["delivery-date"] = new HeaderDeliveryDate();
     fieldMap["priority"] = new HeaderPriority();
     fieldMap["importance"] = new HeaderImportance();
     fieldMap["sensitivity"] = new HeaderSensitivity();
     fieldMap["reply-by"] = new HeaderDate();
     fieldMap["x400-content-identifier"] = new HeaderX400ContentIdentifier();
     fieldMap["x400-received"] = new HeaderX400Received();
     fieldMap["x400-mts-identifier"] = new HeaderX400MtsIdentifier();
     fieldMap["x400-trace"] = new HeaderX400Received();
     fieldMap["x400-originator"] = new HeaderX400Originator();
     fieldMap["x400-recipients"] = new HeaderX400Recipients();
     fieldMap["conversion"] = new HeaderConversion();
     fieldMap["conversion-with-loss"] = new HeaderConversionWithLoss();
     fieldMap["supersedes"] = new HeaderSupersedes();
     fieldMap["expires"] = new HeaderDate();
     fieldMap["autoforwarded"] = new HeaderAutoforwarded();
     fieldMap["generate-delivery-report"] = new HeaderGenerateDeliveryReport();
     fieldMap["incomplete-copy"] = new HeaderIncompleteCopy();
     fieldMap["prevent-nondelivery-report"] = new HeaderPreventNondeliveryReport();
     fieldMap["alternate-recipient"] = new HeaderAlternateRecipient();
     fieldMap["disclose-recipients"] = new HeaderDiscloseRecipients();
     fieldMap["expanded-date"] = new HeaderExpandedDate();
     fieldMap["newsgroups"] = new HeaderNewsgroups();
     fieldMap["path"] = new HeaderPath();
     fieldMap["archive"] = new HeaderArchive();
     fieldMap["control"] = new HeaderControl();
     fieldMap["distribution"] = new HeaderDistribution();
     fieldMap["followup-to"] = new HeaderFollowupTo();
     fieldMap["injection-date"] = new HeaderInjectionDate();
     fieldMap["injection-info"] = new HeaderInjectionInfo();
     fieldMap["user-agent"] = new HeaderUserAgent();
     fieldMap["xref"] = new HeaderXref();
     fieldMap["nntp-posting-date"] = new HeaderInjectionDate();
     fieldMap["nntp-posting-host"] = new HeaderNntpPostingHost();
     fieldMap["accept-language"] = new HeaderAcceptLanguage();
     fieldMap["archived-at"] = new HeaderArchivedAt();
     fieldMap["authentication-results"] = new HeaderAuthenticationResults();
     fieldMap["auto-submitted"] = new HeaderAutoSubmitted();
     fieldMap["base"] = new HeaderContentBase();
     fieldMap["bcc"] = new HeaderBcc();
     fieldMap["cc"] = new HeaderTo();
     fieldMap["content-base"] = new HeaderContentBase();
     fieldMap["content-disposition"] = new HeaderContentDisposition();
     fieldMap["content-duration"] = new HeaderContentDuration();
     fieldMap["content-id"] = new HeaderContentId();
     fieldMap["content-language"] = new HeaderContentLanguage();
     fieldMap["content-location"] = new HeaderContentLocation();
     fieldMap["content-md5"] = new HeaderContentMd5();
     fieldMap["content-transfer-encoding"] = new HeaderContentTransferEncoding();
     fieldMap["content-type"] = new HeaderContentType();
     fieldMap["date"] = new HeaderDate();
     fieldMap["deferred-delivery"] = new HeaderDeferredDelivery();
     fieldMap["disposition-notification-options"] = new
       HeaderDispositionNotificationOptions();
     fieldMap["disposition-notification-to"] = new HeaderDispositionNotificationTo();
     fieldMap["mmhs-authorizing-users"] = new HeaderMmhsAuthorizingUsers();
     fieldMap["dkim-signature"] = new HeaderDkimSignature();
     fieldMap["ediint-features"] = new HeaderEdiintFeatures();
     fieldMap["eesst-version"] = new HeaderEesstVersion();
     fieldMap["encoding"] = new HeaderEncoding();
     fieldMap["encrypted"] = new HeaderEncrypted();
     fieldMap["expiry-date"] = new HeaderDate();
     fieldMap["from"] = new HeaderFrom();
     fieldMap["in-reply-to"] = new HeaderInReplyTo();
     fieldMap["jabber-id"] = new HeaderJabberId();
     fieldMap["keywords"] = new HeaderKeywords();
     fieldMap["language"] = new HeaderLanguage();
     fieldMap["latest-delivery-time"] = new HeaderLatestDeliveryTime();
     fieldMap["list-id"] = new HeaderListId();
     fieldMap["message-context"] = new HeaderMessageContext();
     fieldMap["message-id"] = new HeaderMessageId();
     fieldMap["mime-version"] = new HeaderMimeVersion();
     fieldMap["mmhs-acp127-message-identifier"] = new
       HeaderMmhsAcp127MessageIdentifier();
     fieldMap["mmhs-codress-message-indicator"] = new
       HeaderMmhsCodressMessageIndicator();
     fieldMap["mmhs-copy-precedence"] = new HeaderMmhsCopyPrecedence();
     fieldMap["mmhs-exempted-address"] = new HeaderMmhsExemptedAddress();
     fieldMap["mmhs-extended-authorisation-info"] = new
       HeaderMmhsExtendedAuthorisationInfo();
     fieldMap["mmhs-handling-instructions"] = new HeaderMmhsHandlingInstructions();
     fieldMap["mmhs-message-instructions"] = new HeaderMmhsMessageInstructions();
     fieldMap["mmhs-message-type"] = new HeaderMmhsMessageType();
     fieldMap["mmhs-originator-plad"] = new HeaderMmhsOriginatorPlad();
     fieldMap["mmhs-originator-reference"] = new HeaderMmhsOriginatorReference();
     fieldMap["mmhs-other-recipients-indicator-cc"] = new
       HeaderMmhsOtherRecipientsIndicatorCc();
     fieldMap["mmhs-other-recipients-indicator-to"] = new
       HeaderMmhsOtherRecipientsIndicatorTo();
     fieldMap["mmhs-primary-precedence"] = new HeaderMmhsPrimaryPrecedence();
     fieldMap["mmhs-subject-indicator-codes"] = new
       HeaderMmhsSubjectIndicatorCodes();
     fieldMap["mt-priority"] = new HeaderMtPriority();
     fieldMap["obsoletes"] = new HeaderObsoletes();
     fieldMap["original-from"] = new HeaderFrom();
     fieldMap["original-message-id"] = new HeaderMessageId();
     fieldMap["original-recipient"] = new HeaderOriginalRecipient();
     fieldMap["received"] = new HeaderReceived();
     fieldMap["received-spf"] = new HeaderReceivedSpf();
     fieldMap["references"] = new HeaderInReplyTo();
     fieldMap["reply-to"] = new HeaderResentTo();
     fieldMap["require-recipient-valid-since"] = new
       HeaderRequireRecipientValidSince();
     fieldMap["resent-bcc"] = new HeaderBcc();
     fieldMap["resent-cc"] = new HeaderResentTo();
     fieldMap["resent-date"] = new HeaderDate();
     fieldMap["resent-from"] = new HeaderFrom();
     fieldMap["resent-message-id"] = new HeaderMessageId();
     fieldMap["resent-reply-to"] = new HeaderResentTo();
     fieldMap["resent-sender"] = new HeaderSender();
     fieldMap["resent-to"] = new HeaderResentTo();
     fieldMap["return-path"] = new HeaderReturnPath();
     fieldMap["sender"] = new HeaderSender();
     fieldMap["sio-label"] = new HeaderSioLabel();
     fieldMap["sio-label-history"] = new HeaderSioLabel();
     fieldMap["solicitation"] = new HeaderSolicitation();
     fieldMap["to"] = new HeaderTo();
     fieldMap["vbr-info"] = new HeaderVbrInfo();
     fieldMap["x-archived-at"] = new HeaderXArchivedAt();
     fieldMap["x-mittente"] = new HeaderSender();
     fieldMap["x-ricevuta"] = new HeaderXRicevuta();
     fieldMap["x-riferimento-message-id"] = new HeaderMessageId();
     fieldMap["x-tiporicevuta"] = new HeaderXTiporicevuta();
     fieldMap["x-trasporto"] = new HeaderXTrasporto();
     fieldMap["x-verificasicurezza"] = new HeaderXVerificasicurezza();
       return fieldMap;
 }