コード例 #1
0
        public bool TryAddMessagePart(MessagePart messagePart, int mtuSize)
        {
            byte[] bytes = messagePart.Encode();
            if (bytes.Length + _currentSize > mtuSize)
            {
                return(false);
            }

            if (messagePart.ReliabilityHeader.HasSplit && MessageParts.Count > 0)
            {
                //if (Log.IsDebugEnabled)
                //	Log.Warn($"Message has split and count > 0: {MessageParts.Count}, MTU: {mtuSize}");
                return(false);
            }
            //if (Header.isContinuousSend) return false;

            if (messagePart.ReliabilityHeader.PartCount > 0 && messagePart.ReliabilityHeader.PartIndex > 0)
            {
                Header.IsContinuousSend = true;
            }

            if (FirstMessageId == 0)
            {
                FirstMessageId = messagePart.ContainedMessageId;
            }

            MessageParts.Add(messagePart);
            _currentSize = _currentSize + bytes.Length;

            return(true);
        }
コード例 #2
0
        public bool TryAddMessagePart(MessagePart messagePart, int mtuSize)
        {
            byte[] bytes = messagePart.Encode();
            if (_currentSize + bytes.Length > (mtuSize - RaknetHandler.UdpHeaderSize))
            {
                return(false);
            }

            if (messagePart.ReliabilityHeader.PartCount > 0 && messagePart.ReliabilityHeader.PartIndex > 0)
            {
                Header.IsContinuousSend = true;
            }

            //TODO: Get rid of this stuff.
            if (FirstMessageId == 0)
            {
                FirstMessageId = messagePart.ContainedMessageId;
            }

            MessageParts.Add(messagePart);

            _currentSize += bytes.Length;

            return(true);
        }
コード例 #3
0
 private void AddingMessagePartsToWindow(MessageParts item)
 {
     MessageTheme.Text = item.Subject;
     MessageFrom.Text  = item.From;
     MessageTime.Text  = item.Date;
     MessageWhom.Text  = item.To;
     MessageBody.Text  = item.Body;
 }
コード例 #4
0
 public override void Reset()
 {
     Header.Reset();
     RetransmissionTimeOut = 0;
     TransmissionCount     = 0;
     _currentSize          = 4;
     FirstMessageId        = 0;
     MessageParts.Clear();
     _buf.SetLength(0);
 }
コード例 #5
0
ファイル: Datagram.cs プロジェクト: mattibijnens/MiNET
        public override void Reset()
        {
            Header.Reset();
            RetransmissionTimeOut = 0;
            TransmissionCount     = 0;
            _currentSize          = 4;
            FirstMessageId        = 0;

            foreach (MessagePart part in MessageParts)
            {
                part.PutPool();
            }

            MessageParts.Clear();
            _buf.SetLength(0);
        }
コード例 #6
0
        /// <summary>
        /// Parses the <paramref name="rawBody"/> Byte array as a MultiPart message.<br/>
        /// It is not valid to call this method if <see cref="IsMultiPart"/> returned <see langword="false"/>.<br/>
        /// Fills the <see cref="MessageParts"/> property of this <see cref="MessagePart"/>.
        /// </summary>
        /// <param name="rawBody">The Byte array which is to be parsed as a MultiPart message</param>
        private void ParseMultiPartBody(Byte[] rawBody)
        {
            // Fetch out the boundary used to delimit the messages within the body
            String multipartBoundary = ContentType.Boundary;

            // Fetch the individual MultiPart message parts using the MultiPart boundary
            List <Byte[]> bodyParts = GetMultiPartParts(rawBody, multipartBoundary);

            // Initialize the MessageParts property, with room to as many bodies as we have found
            MessageParts = new List <MessagePart> withCapacity(bodyParts.Count);

            // Now parse each Byte array as a message body and add it the the MessageParts property
            foreach (Byte[] bodyPart in bodyParts)
            {
                MessagePart messagePart = GetMessagePart(bodyPart);
                MessageParts.Add(messagePart);
            }
        }
コード例 #7
0
        public override void Reset()
        {
            base.Reset();

            Header.Reset();
            RetransmissionTimeOut = 0;
            RetransmitImmediate   = false;
            TransmissionCount     = 0;
            _currentSize          = 4;
            FirstMessageId        = 0;

            foreach (MessagePart part in MessageParts)
            {
                part.PutPool();
            }

            MessageParts.Clear();
        }
コード例 #8
0
        public static void UpdateWildcards(this MessageParts sendMessage, DigestMessage originalMessage)
        {
            var dict = new Dictionary <string, string>
            {
                { "$user", originalMessage.FromAccount },
                { "$channel", originalMessage.ChannelName },
                { "$bot", originalMessage.BotUsername },
                { "$time", DateTime.Now.ToString("h:mm tt") },
                { "$day", DateTime.Now.ToString("d") }
            };

            foreach (var thing in sendMessage)
            {
                if (!dict.TryGetValue(thing.Value.ToLower(), out var replace))
                {
                    continue;
                }
                thing.Value = replace;
            }
        }
コード例 #9
0
        /// <summary>
        /// searchs in messages for specified filter, applies it to filtred list and returns it
        /// </summary>
        /// <param name="part">part of mail message within the search will take place  </param>
        /// <param name="search"> kind of search we want to filter</param>
        /// <param name="filter">filter that the method will search by</param>
        /// <returns></returns>
        public List <MimeMessage> FilterBy(MessageParts part, SearchFilters search, string filter)
        {
            switch (part)
            {
            case MessageParts.Subject:
                FilterSubjectBy(search, filter);
                break;

            case MessageParts.Body:
                FilterBodyBy(search, filter);
                break;

            case MessageParts.From:
                FilterFromBy(search, filter);
                break;

            case MessageParts.Date:
                FilterDateBy(search, filter);
                break;
            }
            return(filtred);
        }
コード例 #10
0
        public void Compact()
        {
            // the idea is to glue each text part that has the same attributes
            // to a combined new one to reduce the number of parts as they are
            // expensive when serialized

            // nothing to glue
            if (MessageParts.Count <= 1)
            {
                return;
            }

            var           parts        = new List <MessagePartModel>(MessageParts.Count);
            StringBuilder gluedText    = null;
            bool          dontMoveNext = false;
            var           iter         = MessageParts.GetEnumerator();

            while (dontMoveNext || iter.MoveNext())
            {
                dontMoveNext = false;
                var current = iter.Current;
                parts.Add(current);

                // we can only glue pure text (not URLs etc)
                if (current.GetType() != typeof(TextMessagePartModel))
                {
                    continue;
                }

                var currentText = (TextMessagePartModel)current;
                while (iter.MoveNext())
                {
                    var next = iter.Current;
                    if (next.GetType() != typeof(TextMessagePartModel))
                    {
                        parts.Add(next);
                        break;
                    }

                    var nextText = (TextMessagePartModel)next;
                    if (!currentText.AttributesEquals(nextText))
                    {
                        // they aren't the same! no candidate for glueing :/
                        // but maybe the next part is
                        dontMoveNext = true;
                        break;
                    }

                    // glue time!
                    if (gluedText == null)
                    {
                        // this is the first element of the gluing
                        gluedText = new StringBuilder(256);
                        gluedText.Append(currentText.Text);
                    }
                    gluedText.Append(nextText.Text);
                }

                if (gluedText != null)
                {
                    currentText.Text = gluedText.ToString();
                    gluedText        = null;
                }
            }

            f_MessageParts = parts;
        }
コード例 #11
0
        public void CreateDefect(V1Connector CurrentV1Connection, List <Message> CurrentEmails)
        {
            V1XMLHelper  V1XML        = new V1XMLHelper();
            V1Logging    Logs         = new V1Logging();
            string       ProjectScope = "Something for Testing";
            string       EmailBody;
            MessagePart  MessageParts;
            SMTPResponse V1Response = new SMTPResponse();
            MailChecker  MailCheck  = new MailChecker();

            IServices services = new Services(CurrentV1Connection);


            try
            {
                foreach (Message MailItem in CurrentEmails)
                {
                    for (int ToCtr = 0; ToCtr < MailItem.Headers.To.Count; ToCtr++)
                    {
                        ProjectScope = V1XML.GetProjectScope(MailItem.Headers.To[ToCtr].Address);
                        if (ProjectScope != null)
                        {
                            Oid                  projectId     = services.GetOid(ProjectScope);
                            IAssetType           defectType    = services.Meta.GetAssetType("Defect");
                            Asset                NewDefect     = services.New(defectType, projectId);
                            IAttributeDefinition nameAttribute = defectType.GetAttributeDefinition("Name");
                            NewDefect.SetAttributeValue(nameAttribute, MailItem.Headers.Subject.ToString());

                            MessageParts = MailItem.FindFirstHtmlVersion();
                            if (MessageParts == null)
                            {
                                MessageParts = MailItem.FindFirstPlainTextVersion();
                            }
                            EmailBody = MessageParts.GetBodyAsText();

                            Logs.LogEvent("Operation - Creating Defect for " + MailItem.Headers.To[ToCtr].Address);

                            IAttributeDefinition descriptionAttribute = defectType.GetAttributeDefinition("Description");
                            NewDefect.SetAttributeValue(descriptionAttribute, EmailBody);
                            IAttributeDefinition FoundByAttribute = defectType.GetAttributeDefinition("FoundBy");
                            NewDefect.SetAttributeValue(FoundByAttribute, MailItem.Headers.From.ToString());
                            services.Save(NewDefect);

                            IAttributeDefinition DefectIDAttribute = defectType.GetAttributeDefinition("Number");
                            Query IDQuery = new Query(NewDefect.Oid);
                            IDQuery.Selection.Add(DefectIDAttribute);
                            QueryResult ResultID = services.Retrieve(IDQuery);
                            Asset       defect   = ResultID.Assets[0];

                            //NewDefect.GetAttribute(DefectIDAttribute).Value
                            Logs.LogEvent("Operation - Sending Response to Defect Sender.");
                            //Commented out the Response back to the Sender per John Waedekin
                            //V1Response.SendResponse(MailItem, defect.GetAttribute(DefectIDAttribute).Value + " " + NewDefect.GetAttribute(nameAttribute).Value, ProjectScope);
                            MailCheck.DeleteMessagesOnServer(MailItem, ProjectScope);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logs.LogEvent("ERROR - Creating Defect - " + ex.InnerException.Message);
            }
        }
コード例 #12
0
        //---------------------IMAP------MailKit-------------------------------


        public static async Task <List <MessageParts> > CustomsDownloadBodyPartsAsync(Account element, string FolderName, BinarySearchQuery queryCustom)
        {
            List <MessageParts> MessagesListRender = new List <MessageParts>();
            List <IMailFolder>  myListFolders      = new List <IMailFolder>();

            using (var client = new ImapClient())
            {
                await client.ConnectAsync(element.IMAPServerDetails, element.IMAPPortDetails, SecureSocketOptions.SslOnConnect);

                await client.AuthenticateAsync(element.IMAPEmailAddress, element.IMAPEmailBoxPassword);

                await client.Inbox.OpenAsync(FolderAccess.ReadOnly);

                var personal = client.GetFolder(client.PersonalNamespaces[0]);

                IMailFolder CompleteFolder = personal.GetSubfolders()[1];

                foreach (var folder in CompleteFolder.GetSubfolders())
                {
                    myListFolders.Add(folder);
                }

                int indexOfFolder = myListFolders.FindIndex(a => a.Name == FolderName);
                if (indexOfFolder > 0)
                {
                    await myListFolders[indexOfFolder].OpenAsync(FolderAccess.ReadOnly);

                    if (queryCustom == null)
                    {
                        DateTime DateNow = new DateTime();
                        DateNow = DateTime.Now;
                        var query = SearchQuery.DeliveredAfter(new DateTime(2019, 05, 01)).And(SearchQuery.DeliveredBefore(DateNow));
                        var uids  = await myListFolders[indexOfFolder].SearchAsync(query);
                        const MessageSummaryItems SummaryItems = MessageSummaryItems.UniqueId | MessageSummaryItems.Envelope | MessageSummaryItems.Flags | MessageSummaryItems.BodyStructure;
                        var timeout = new CancellationToken();
                        MessagesList = await myListFolders[indexOfFolder].FetchAsync(uids, SummaryItems, timeout);
                    }
                    if (queryCustom != null)
                    {
                        var uids = myListFolders[indexOfFolder].Search(queryCustom);
                        const MessageSummaryItems SummaryItems = MessageSummaryItems.UniqueId | MessageSummaryItems.Envelope | MessageSummaryItems.Flags | MessageSummaryItems.BodyStructure;
                        var timeout = new CancellationToken();
                        MessagesList = await myListFolders[indexOfFolder].FetchAsync(uids, SummaryItems, timeout);
                    }

                    foreach (var message in MessagesList)
                    {
                        MessageParts temp = new MessageParts();
                        temp.Uid = message.UniqueId.ToString();

                        var bodyPart = message.TextBody;
                        var body     = (TextPart)myListFolders[indexOfFolder].GetBodyPart(message.UniqueId, bodyPart);
                        temp.Body = body.Text;

                        string str   = message.Envelope.Date.ToString();
                        int    index = str.IndexOf("+") > 0 ? str.IndexOf("+") : str.IndexOf("-");
                        temp.Date = str.Substring(0, index);

                        temp.From    = message.Envelope.From.ToString();
                        temp.Cc      = message.Envelope.Cc.ToString();
                        temp.Subject = message.Envelope.Subject.ToString();
                        temp.To      = message.Envelope.To.ToString();
                        MessagesListRender.Add(temp);
                    }
                }
                client.Disconnect(true);
            }
            return(MessagesListRender);
        }