亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? mailboxreader.cs

?? BugNET is an issue tracking and project issue management solution built using the ASP.NET web applic
?? CS
字號:
using System;
using System.Configuration;
using System.Web;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Collections;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Drawing.Imaging;
using BugNET.BusinessLogicLayer;
//using IssueAttachment = BugNET.BusinessLogicLayer.IssueAttachment;
using Lesnikowski.Client;
using Lesnikowski.Mail;
using MailAttachment = Lesnikowski.Mail.MimeData;
using log4net;
using log4net.Config;

namespace BugNET.POP3Reader
{
    /// <summary>
    /// This is the handler class for the Mail-To-Weblog functionality.
    /// </summary>
    public class MailboxReader
    {
		string Pop3Server;
		string Pop3Username;
		string Pop3Password;
		bool Pop3InlineAttachedPictures;
		bool Pop3DeleteAllMessages;
		string ReportingUserName;
		string BodyTemplate;

        private static readonly ILog Log = LogManager.GetLogger(typeof(MailboxReader));

        /// <summary>
        /// Processes the exception.
        /// </summary>
        /// <param name="ex">The exception.</param>
        /// <returns></returns>
        private ApplicationException ProcessException(Exception ex)
        {
            //set user to log4net context, so we can use %X{user} in the appenders
            if (System.Web.HttpContext.Current.User != null && System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
                MDC.Set("user", System.Web.HttpContext.Current.User.Identity.Name);

            if (Log.IsErrorEnabled)
                Log.Error("Mailbox Reader Error", ex);

            //TODO: Get this from a resource string.
            return new ApplicationException("An error has occured in processing the mailbox reader.", ex);
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="T:MailboxReader"/> class.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="userName">Name of the user.</param>
        /// <param name="password">The password.</param>
        /// <param name="inlineAttachedPictures">if set to <c>true</c> [inline attached pictures].</param>
        /// <param name="bodyTemplate">The body template.</param>
        /// <param name="deleteAllMessages">if set to <c>true</c> [delete all messages].</param>
        /// <param name="reportingUserName">Name of the reporting user.</param>
        public MailboxReader(string server, string userName, string password, 
             bool inlineAttachedPictures, string bodyTemplate, 
            bool deleteAllMessages, string reportingUserName)
        {
            Pop3Server = server;
            Pop3Username = userName;
            Pop3Password = password;
        
            Pop3InlineAttachedPictures = inlineAttachedPictures;
            BodyTemplate = bodyTemplate;
            Pop3DeleteAllMessages = deleteAllMessages;
            ReportingUserName = reportingUserName;
		}

        /// <summary>
        /// Compares two binary buffers up to a certain length.
        /// </summary>
        /// <param name="buf1">First buffer</param>
        /// <param name="buf2">Second buffer</param>
        /// <param name="len">Length</param>
        /// <returns>true or false indicator about the equality of the buffers</returns>
        private bool EqualBuffers( byte[] buf1, byte[] buf2, int len )
        {
            if ( buf1.Length >= len && buf2.Length >= len )
            {
                for( int l=0;l<len;l++)
                {
                    if ( buf1[l]!=buf2[l])
                        return false;
                }
                return true;
            }
            return false;
        }

        /// <summary>
        /// Stores an attachment to disk.
        /// </summary>
        /// <param name="attachment"></param>
        /// <param name="binariesPath"></param>
        /// <returns></returns>
        public string StoreAttachment( MailAttachment attachment, string binariesPath )
        {
            bool alreadyUploaded = false;
            string baseFileName = attachment.FileName;
            string targetFileName = Path.Combine(binariesPath, baseFileName);
            int numSuffix=1;
                            
            // if the target filename already exists, we check whether we already 
            // have that file stored by comparing the first 2048 bytes of the incoming
            // date to the target file (creating a hash would be better, but this is 
            // "good enough" for the time being)
            while ( File.Exists(targetFileName))
            {
                byte[] targetBuffer=new byte[Math.Min(2048, attachment.Data.Length)];
                int targetBytesRead;

                using(FileStream targetFile = new FileStream(targetFileName,FileMode.Open,FileAccess.Read,FileShare.Read))
                {
                    long numBytes = targetFile.Length;
                    if ( numBytes == (long)attachment.Data.Length )
                    {
                        targetBytesRead = targetFile.Read(targetBuffer,0,targetBuffer.Length);
                        if ( targetBytesRead == targetBuffer.Length )
                        {
                            if ( EqualBuffers(targetBuffer, attachment.Data, targetBuffer.Length ) )
                            {
                                alreadyUploaded=true;
                            }
                        }
                    }
                }

                // If the file names are equal, but it's not considered the same file,
                // we append an incrementing numeric suffix to the file name and retry.
                if ( !alreadyUploaded )
                {
                    string ext = Path.GetExtension(baseFileName);
                    string file = Path.GetFileNameWithoutExtension(baseFileName);
                    string newFileName = file + (numSuffix++).ToString();
                    baseFileName = newFileName+ext;
                    targetFileName = Path.Combine(binariesPath,baseFileName);
                }
                else
                {
                    break;
                }
            }
                                            
            // now we've got a unique file name or the file is already stored. If it's
            // not stored, write it to disk.
            if ( !alreadyUploaded )
            {
                using(FileStream fileStream = new FileStream(targetFileName,FileMode.Create))
                {
                    fileStream.Write(attachment.Data, 0, attachment.Data.Length);
                    fileStream.Flush();
                }
            }
            return baseFileName;
        }

        /// <summary>
        /// Saves the entry.
        /// </summary>
        /// <param name="entry">The entry.</param>
		void SaveEntry(Entry entry)
		{
			try
			{
                string body = string.Format(this.BodyTemplate, entry.Content.ToString().Trim(), entry.From, entry.Date.ToString());

                //Issue newBug = new Issue(entry.ProjectMailbox.ProjectId, entry.Title.Trim(), body, 0,0,(int)Globals.PriorityType.Minor, 1, 1,Globals.DefaultId,entry.ProjectMailbox.AssignToName, ReportingUserName,0,0,DateTime.MinValue);

                //if (newBug.Save())
                //{
                //    //If there is an attached file present then add it to the database 
                //    //and copy it to the directory specified in the web.config file
                //    for (int i = 0; i < entry.AttachmentFileNames.Count; i++)
                //    {
                //        MailAttachment attMail = entry.MailAttachments[i] as MailAttachment;
                //        IssueAttachment att = new IssueAttachment(newBug.Id, Path.GetFileName(entry.AttachmentFileNames[i].ToString()), entry.AttachmentFileNames[i].ToString(), attMail.Data.Length, attMail.ContentType.ToString(), ReportingUserName);
                //        att.Save();
                //    }
                //}
			}
			catch(Exception ex)
			{
                throw ProcessException(ex);
			}
		}

        /// <summary>
        /// ReadMail reads the pop3 mailbox
        /// </summary>
        public void ReadMail()
        {    
				Pop3 pop3=new Pop3();
                        
				try
				{
					try
					{
						pop3.User = Pop3Username;
						pop3.Password = Pop3Password;

						pop3.Connect(Pop3Server);
                        if (pop3.HasTimeStamp == true)
                            pop3.Login();//APOPLogin();
                        else
                            pop3.Login();
						
						pop3.GetAccountStat();

						int j = 1;

						bool messageWasProcessed = false; 

						for (;j <= pop3.MessageCount; j++)
						{
							SimpleMailMessage message = SimpleMailMessage.Parse(pop3.GetMessage(j));

							string messageFrom = "";

							if (message.From.Count > 0)
							{
								MailBox from = message.From[0];
								messageFrom = from.Address;
							}

							// E-Mail addresses look usually like this:
							// My Name <myname@example.com> or simply
							// myname@example.com. This block handles 
							// both variants.\
                           
							MailBox[] recipients = (MailBox[])message.To.ToArray();
							foreach (MailBox to in recipients)
							{
								string mailbox = to.Address;

								ProjectMailbox pmbox = ProjectMailbox.GetProjectByMailbox(mailbox);

								// Only if the mailbox appears in project's mailbox aliases
								// we accept the message
								if ( pmbox != null)
								{
									string binariesBaseUri;
									string binariesPath;

									string uploadPath = Project.GetProjectById(pmbox.ProjectId).UploadPath.TrimEnd('/');
	
									string appPath = HostSetting.GetHostSetting("DefaultUrl");

									if (uploadPath.StartsWith("~"))
									{
										binariesPath = uploadPath.Replace("~", appPath.TrimEnd('\\'));
									
										binariesBaseUri = uploadPath.Replace("~\\", Globals.DefaultUrl).Replace("\\", "/");
									}
									else
									{
										binariesPath = string.Concat(appPath, "Uploads\\");
									
										binariesBaseUri = string.Concat(Globals.DefaultUrl, "Uploads/");
									}

									Entry entry = new Entry();

									entry.Title = message.Subject.Trim();
									entry.From = messageFrom;
									entry.ProjectMailbox = pmbox;

									entry.Date = message.Date;

									// plain text?
									if ( message.HtmlDataString.Length == 0)
									{
										entry.Content.Append(message.TextDataString);
									}
									else
									{
										// Strip the <body> out of the message (using code from below)
										Regex bodyExtractor = new Regex("<body.*?>(?<content>.*)</body>",RegexOptions.IgnoreCase|RegexOptions.Singleline);
										Match match = bodyExtractor.Match( message.HtmlDataString );
										if ( match != null && match.Success && match.Groups["content"] != null )
										{
											entry.Content.Append(match.Groups["content"].Value);
										}
										else
										{
											entry.Content.Append(message.HtmlDataString);
										}
									}									

									Hashtable embeddedFiles = new Hashtable();
									ArrayList attachedFiles = new ArrayList();

									foreach( MailAttachment attachment in message.Attachments )
									{
										if ( attachment.Data != null && attachment.FileName != null && attachment.FileName.Length > 0)
										{
											string fn = StoreAttachment( attachment, binariesPath );

											entry.MailAttachments.Add(attachment);
											entry.AttachmentFileNames.Add(fn);
                                                
											attachedFiles.Add(fn);
										}
									}

									if ( entry.MailAttachments.Count > 0 )
									{
										entry.Content.Append("<p>");

										for(int i=0; i < entry.MailAttachments.Count; i++ )
										{
											MailAttachment attachment = (MailAttachment) entry.MailAttachments[i];

											string absoluteUri = string.Concat( binariesBaseUri, entry.AttachmentFileNames[i] );
											if (Pop3InlineAttachedPictures && attachment.ContentType.MimeType == MimeType.Image)
											{
												entry.Content.Append(String.Format("<br><img src=\"{0}\" />",absoluteUri));
											}
											else
											{
												entry.Content.Append(String.Format("<br><a href=\"{0}\" />{1}</a>",absoluteUri, attachment.FileName));
											}
										}

										entry.Content.Append("</p>");
									}
                                        
									messageWasProcessed = true;

									SaveEntry(entry);	
								}
								else
								{
                                    if (Log.IsWarnEnabled)
                                        Log.WarnFormat("Project Mailbox Not Found: {0}", message.To.ToString());
								}
							}
							// luke@jurasource.co.uk (01-MAR-04)
							if ( Pop3DeleteAllMessages || messageWasProcessed )
								pop3.DeleteMessage(j);
						}
					}
					catch(Exception ex)
					{
                        throw ProcessException(ex);
					}
				}
				catch(Exception ex)
				{
                    throw ProcessException(ex);
				}
				finally
				{
					pop3.Close();
				}
        }
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美人牲a欧美精品| 国产精品二三区| 国产日韩精品一区| 亚洲最大的成人av| 国产乱淫av一区二区三区| 日本电影亚洲天堂一区| 久久久www免费人成精品| 香蕉av福利精品导航| 不卡的av中国片| 久久综合久久鬼色| 偷窥国产亚洲免费视频| 91无套直看片红桃| 国产日本欧美一区二区| 喷白浆一区二区| 欧美午夜宅男影院| 亚洲欧洲综合另类在线 | 日韩视频一区在线观看| 综合欧美亚洲日本| 成人免费视频一区| 国产亚洲欧洲997久久综合 | 一区在线观看免费| 国产精品影音先锋| 久久综合丝袜日本网| 秋霞成人午夜伦在线观看| 欧美日韩精品一区视频| 亚洲午夜av在线| 欧洲视频一区二区| 最新热久久免费视频| 成人18精品视频| 中文av一区特黄| 成人性生交大合| 国产精品乱码人人做人人爱 | 亚洲成av人在线观看| 欧美性大战久久久| 夜夜揉揉日日人人青青一国产精品| 成人av动漫在线| 成人欧美一区二区三区视频网页| 国产成人一区在线| 国产精品美女久久福利网站| 成人18精品视频| 一区二区三区欧美视频| 色88888久久久久久影院野外 | 99国产精品久久久| 亚洲视频免费在线| 欧美性猛交xxxx黑人交| 日韩电影在线观看电影| 欧美成人乱码一区二区三区| 精品一区二区三区免费毛片爱 | 国产在线一区观看| 中文天堂在线一区| 色综合久久综合网| 亚洲国产另类精品专区| 91精品综合久久久久久| 国内外成人在线| 国产偷v国产偷v亚洲高清| 97久久超碰国产精品| 亚洲国产精品一区二区www| 777奇米成人网| 国产成人精品一区二区三区网站观看| 国产日韩亚洲欧美综合| 色成人在线视频| 久久精品国产在热久久| 国产精品色眯眯| 欧美日韩国产首页| 国产一区二区三区高清播放| 亚洲欧洲av一区二区三区久久| 欧美日韩亚洲另类| 国产成人精品在线看| 亚洲自拍都市欧美小说| 精品国产凹凸成av人导航| 91在线视频播放地址| 日韩国产精品久久久久久亚洲| 久久综合中文字幕| 欧美伊人久久久久久久久影院| 蜜桃av一区二区| 自拍视频在线观看一区二区| 日韩一区二区不卡| 91麻豆精东视频| 国产精品99久久久久久久女警 | 国产制服丝袜一区| 亚洲综合清纯丝袜自拍| 久久九九影视网| 91麻豆精品国产无毒不卡在线观看 | 欧美精三区欧美精三区| 成人av电影免费在线播放| 秋霞国产午夜精品免费视频| 亚洲精品日韩综合观看成人91| 日韩精品中文字幕一区二区三区| a亚洲天堂av| 国产一区91精品张津瑜| 日韩电影在线免费看| 亚洲人成在线观看一区二区| 久久中文字幕电影| 欧美大白屁股肥臀xxxxxx| 日本久久电影网| 99精品久久免费看蜜臀剧情介绍| 国精产品一区一区三区mba视频| 午夜不卡av在线| 亚洲一区日韩精品中文字幕| 中文字幕人成不卡一区| 久久久久久97三级| 日韩精品中文字幕在线不卡尤物| 欧美视频三区在线播放| 色中色一区二区| 91视频.com| 99精品国产热久久91蜜凸| 午夜精品福利久久久| 中文字幕亚洲在| 欧美肥妇free| 色婷婷精品久久二区二区蜜臂av | 欧美色男人天堂| 一本色道久久综合亚洲aⅴ蜜桃 | 欧美揉bbbbb揉bbbbb| thepron国产精品| 成人午夜激情在线| 成人av在线一区二区| www.视频一区| 一本大道久久a久久精品综合| 成人精品一区二区三区中文字幕| 国产精品18久久久久久久网站| 黄网站免费久久| 国产精品18久久久久久久网站| 国内精品不卡在线| 国产成人av福利| 懂色一区二区三区免费观看| 成人黄色在线视频| 一本色道久久综合亚洲91| 在线观看不卡一区| 这里只有精品免费| 久久噜噜亚洲综合| 国产精品久久久久久久久晋中| 日韩一区在线免费观看| 一区二区三区在线影院| 日韩和欧美一区二区| 久久99久久精品| 成人激情午夜影院| 色猫猫国产区一区二在线视频| 91国偷自产一区二区三区成为亚洲经典 | 欧美午夜精品一区二区蜜桃| 欧美剧在线免费观看网站| 欧美一区二区三区在线电影| 26uuu精品一区二区三区四区在线 26uuu精品一区二区在线观看 | 亚洲国产高清在线| 亚洲精品乱码久久久久久日本蜜臀| 亚洲一区在线视频观看| 美女视频免费一区| 成人av电影免费在线播放| 欧美日韩在线播放三区四区| 日韩精品一区二区三区中文精品| 久久夜色精品国产欧美乱极品| 国产精品国产成人国产三级 | 9191国产精品| 国产亚洲综合在线| 一区二区三区国产精华| 久久草av在线| 色菇凉天天综合网| 久久亚洲捆绑美女| 一区二区三区毛片| 国产精品99久久久久久久vr| 欧美亚洲一区二区在线观看| 国产亚洲va综合人人澡精品| 一区二区高清免费观看影视大全 | 北条麻妃国产九九精品视频| 欧美绝品在线观看成人午夜影视| 久久久综合视频| 日韩av成人高清| 91麻豆精品在线观看| 久久伊人蜜桃av一区二区| 婷婷成人激情在线网| 99久久99精品久久久久久 | 国产精品情趣视频| 免费精品视频在线| 欧美做爰猛烈大尺度电影无法无天| 国产婷婷色一区二区三区| 蜜臀va亚洲va欧美va天堂| 色吊一区二区三区| 综合久久久久久| 成人白浆超碰人人人人| 欧美精品一区二区三区蜜桃视频| 亚洲精品国产精华液| 福利一区二区在线| 久久久国产精品午夜一区ai换脸| 五月激情综合色| 91高清视频在线| 亚洲天堂网中文字| 成人精品一区二区三区中文字幕| 精品久久久久久无| 老色鬼精品视频在线观看播放| 欧美精品电影在线播放| 洋洋av久久久久久久一区| 97久久精品人人做人人爽| 国产清纯在线一区二区www| 国产最新精品免费| 久久久久久久精| 国产精品伊人色| 国产丝袜美腿一区二区三区| 国产成人自拍网| 久久久精品人体av艺术| 国产精品一卡二| 国产精品三级视频|