Esempio n. 1
0
        public void Send(InternetMailMessage message,
                         InternetMailTextProcessing processText = InternetMailTextProcessing.Process,
                         InternetMailProtocol protocol          = InternetMailProtocol.Smtp)
        {
            if (protocol == InternetMailProtocol.Pop3)
            {
                throw new RuntimeException("Недопустимо указывать POP3 в качестве протокола отправки почты!");
            }

            IMailSender sender = null;

            if (protocol == InternetMailProtocol.Smtp)
            {
                sender = smtpClient;
            }
            else if (protocol == InternetMailProtocol.Imap)
            {
                sender = receiver as ImapReceiver;
                if (sender == null)
                {
                    throw new RuntimeException("Соединение IMAP не установлено!");
                }
            }

            sender?.Send(message, processText);
        }
Esempio n. 2
0
        public ArrayImpl Get(bool deleteMessages, ArrayImpl ids, bool markAsRead)
        {
            if (markAsRead != true)
            {
                throw RuntimeException.InvalidArgumentValue();                 // TODO: Внятное сообщение
            }
            var result = new ArrayImpl();

            var processedMessages = GetMessagesList(ids);

            foreach (var i in processedMessages)
            {
                var mimeMessage = client.GetMessage(i);

                var iMessage = new InternetMailMessage(mimeMessage, client.GetMessageUid(i));
                result.Add(iMessage);
            }

            if (deleteMessages && processedMessages.Count > 0)
            {
                client.DeleteMessages(processedMessages);
                Relogon();
            }

            return(result);
        }
Esempio n. 3
0
        public ArrayImpl Get(bool deleteMessages, ArrayImpl ids, bool markAsRead)
        {
            var result            = new ArrayImpl();
            var processedMessages = GetMessagesList(ids);

            foreach (var i in processedMessages)
            {
                var mimeMessage = _currentFolder.GetMessage(i);
                var iMessage    = new InternetMailMessage(mimeMessage, UniqueIdToInternalId(i));
                result.Add(iMessage);
            }

            if (processedMessages.Count > 0)
            {
                if (deleteMessages)
                {
                    _currentFolder.AddFlags(processedMessages, MessageFlags.Deleted, silent: true);
                }
                else if (markAsRead)
                {
                    _currentFolder.AddFlags(processedMessages, MessageFlags.Seen, silent: true);
                }
            }

            return(result);
        }
Esempio n. 4
0
        public InternetMailAttachment Add(InternetMailMessage data, string attachmentName = "")
        {
            var attachment = new InternetMailAttachment();

            attachment.Data = data;
            attachment.Name = attachmentName;
            _data.Add(attachment);
            return(attachment);
        }
Esempio n. 5
0
        public ArrayImpl GetHeaders(StructureImpl filter)
        {
            var result = new ArrayImpl();

            if (client.Count > 0)
            {
                var allHeaders = client.GetMessageHeaders(0, client.Count);

                foreach (var headers in allHeaders)
                {
                    var mailMessage = new InternetMailMessage(headers);
                    result.Add(mailMessage);
                }
            }

            return(result);
        }
Esempio n. 6
0
        public ArrayImpl GetHeaders(StructureImpl filter)
        {
            var result = new ArrayImpl();

            var dataToFetch = MessageSummaryItems.Envelope
                              | MessageSummaryItems.Flags
                              | MessageSummaryItems.UniqueId
                              | MessageSummaryItems.InternalDate
                              | MessageSummaryItems.MessageSize
            ;

            IList <IMessageSummary> allHeaders;

            if (filter == null)
            {
                allHeaders = _currentFolder.Fetch(0, -1, dataToFetch);
            }
            else
            {
                var ids = SearchMessages(filter);
                if (ids.Count == 0)
                {
                    return(result);
                }

                allHeaders = _currentFolder.Fetch(ids, dataToFetch);
            }

            foreach (var headers in allHeaders)
            {
                var mailMessage = new InternetMailMessage(headers);

                mailMessage.Uid.Add(ValueFactory.Create(UniqueIdToInternalId(headers.UniqueId)));
                result.Add(mailMessage);
            }

            return(result);
        }
Esempio n. 7
0
        public void Send(InternetMailMessage message, InternetMailTextProcessing processText)
        {
            var messageToSend = message.CreateNativeMessage(processText);

            _client.Send(messageToSend);
        }