示例#1
0
 public void 全メール削除()
 {
     Response response;
     using (var pop3 = new Pop3())
     {
         pop3.Connect(_server, _port, _secure);
         pop3.Login(_userName, _password);
         response = pop3.GetMessageItems();
         // 全部消す
         foreach (var item in response.Items.Where(i => i.No > TestMailMaxNo))
         {
             pop3.CommandDele(item.No);
         }
         pop3.CommandQuit();
     }
 }
示例#2
0
        private void InternalReceive(string uploadingPath, Pop3 pop3, MessageItem item)
        {
            Trace.WriteLine(string.Format(" retr mail {0}  : {1}", item.No, DateTime.Now));
            var message = pop3.CommandRetr(item.No);
            var delete = true;
            if (message.Successed)
            {
                var subject = "メール投稿 " + message.Message.Header("Subject");
                var sender = message.Message.Header("From");
                var senderHash = PhotosService.GetStringHash(sender);
                var messageId = message.Message.Header("Message-ID");

                var textPart = message.Message.FirstTextPlainMultipart();
                var text = textPart != null
                    ? Mime.DecodeString(textPart.Encoding, textPart.Charset, textPart.BodySource).Trim()
                    : "";
                var description = text;

                if (_repository.GetPhoto(messageId) == null)
                {
                    var images = message.Message
                        .Multiparts
                        .Where(m => m.Body.ContentType.StartsWith("image/"));

                    Trace.WriteLine(string.Format(" save photos {0}({1})  : {2}", item.No, images.Count(), DateTime.Now));
                    foreach (var image in images)
                    {
                        var ext = ImageResizer.GetMimeToExtension(image.Body.ContentType);
                        var photo = InternalSaveMultipart(uploadingPath, image, string.Format("original.{0}", ext));
                        photo.ImportTags(Tag.ToTags(subject.Split(' ')));
                        photo.MessageId = messageId;
                        photo.Description = description;

                        // メールアドレスを削除コードにする。
                        photo.DeleteCode = senderHash;
                        photo.Sender = senderHash;

                        _repository.Append(photo);
                        _repository.SaveChanges();
                    }
                }
                else
                {
                    // 他のホストで取り出し中のはず
                    delete = false;
                }
            }

            if (delete)
                pop3.CommandDele(item.No);

            Trace.WriteLine(string.Format(" dele mail {0}  : {1}", item.No, DateTime.Now));
        }
示例#3
0
        public void メッセージを削除()
        {
            SendTestMail(_userName);

            Response response;
            using (var pop3 = new Pop3())
            {
                response = pop3.Connect(_server, _port, _secure);

                Console.WriteLine(response.Trace);

                response = pop3.Login(_userName, _password);
                Console.WriteLine(response.Trace);

                response = pop3.GetMessageItems();
                Console.WriteLine(response.Trace);
                Console.WriteLine(response.Items.Count + " messages");

                // 全部消す
                foreach (var item in response.Items.Where(i => i.No > TestMailMaxNo))
                {
                    response = pop3.CommandDele(item.No);
                    Assert.IsTrue(response.Successed);
                    Console.WriteLine(response.Trace);
                }
                response = pop3.CommandQuit();
                Console.WriteLine(response.Trace);
            }

            Assert.IsTrue(response.Successed);
        }