Example #1
0
        static void Main(string[] args)
        {
            #region 获取包含所有日志链接的HTML文本
            //string baseQueryUrl = "http://www.douban.com/people/oranjeruud/notes?start=";
            //for (int i = 0; i < 23; i++)
            //{
            //    string queryUrl = baseQueryUrl + (i * 10);
            //    HttpWebRequest httpWebRequest = HttpWebRequest.CreateHttp(queryUrl);
            //    httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95";
            //    HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();//取得响应
            //    if (httpWebResponse.StatusCode.Equals(HttpStatusCode.OK))//若响应状态码为200,说明成功,可以分析得到的数据
            //    {
            //        StreamReader reader = new StreamReader(new BufferedStream(httpWebResponse.GetResponseStream(), 4 * 200 * 1024));
            //        GetBlogLink(reader.ReadToEnd());
            //        reader.Close();
            //    }
            //    Thread.Sleep(3000);
            //}
            #endregion

            #region 根据获得的日志链接获取日志网页和mht文件
            Message           msg = new CDO.MessageClass();
            CDO.Configuration c   = new CDO.ConfigurationClass();
            msg.Configuration = c;
            StreamReader reader = new StreamReader("links.txt");
            int          i      = 0;
            while (!reader.EndOfStream)
            {
                i++;
                string         link           = reader.ReadLine();
                HttpWebRequest httpWebRequest = HttpWebRequest.CreateHttp(link);
                httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95";
                HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); //取得响应
                if (httpWebResponse.StatusCode.Equals(HttpStatusCode.OK))                        //若响应状态码为200,说明成功,可以分析得到的数据
                {
                    StreamReader httpReader  = new StreamReader(new BufferedStream(httpWebResponse.GetResponseStream(), 4 * 200 * 1024));
                    string       htmlContent = httpReader.ReadToEnd();
                    httpReader.Close();
                    string title = GetBlogTitle(htmlContent);
                    #region 保存为html文件
                    StreamWriter writer = new StreamWriter(i + ".html");
                    writer.Write(htmlContent);
                    writer.Close();
                    #endregion
                    #region 保存为mht文件
                    //msg.HTMLBody = htmlContent;
                    msg.CreateMHTMLBody(link, CDO.CdoMHTMLFlags.cdoSuppressNone, "", "");
                    ADODB.Stream stream = msg.GetStream();
                    stream.SaveToFile(title + ".mht", ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
                    #endregion
                }
                if (i == 1)
                {
                    break;
                }
            }
            reader.Close();
            #endregion
        }
Example #2
0
        //下载并存为mht格式
        public string DownToMHT(string url, string vpath)
        {
            if (!url.Contains("://"))
            {
                throw new Exception("地址必须以http或https开头");
            }
            vpath = SafeSC.PathDeal(vpath).Replace("#", "井").Replace("-", "");//去除掉空格等,否则客户端打开会报错
            string ppath = function.VToP(vpath);
            string dir   = Path.GetDirectoryName(ppath);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            CDO.Message       msg = new CDO.MessageClass();
            CDO.Configuration c   = new CDO.ConfigurationClass();
            msg.Configuration = c;
            msg.CreateMHTMLBody(url, CdoMHTMLFlags.cdoSuppressNone, "", "");//cdoSuppressNone=将全部资源都打包进入,CdoMHTMLFlags.cdoSuppressAll=只保留纯页面
            msg.GetStream().SaveToFile(ppath, ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
            return(vpath);
        }
Example #3
0
        //***************************************************************************
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool SendTo()
        {
            CDO.MessageClass a = new CDO.MessageClass();
            CDO.IBodyPart    ibp;
            CDO.IBodyPart    ibp2;
            ADODB.Fields     flds;
            ADODB.Fields     flds1;
            ADODB.Fields     flds2;

            if (To.Length == 0)
            {
                Console.WriteLine("Error: Must have a \"To\"!\n"); return(false);
            }
            //
            if (From.Length == 0)
            {
                Console.WriteLine("Error: Must have a \"From\"!\n"); return(false);
            }
            //
            if (SMTPServer.Length == 0)
            {
                Console.WriteLine("Error: Must have a \"SMTPServer\"!\n"); return(false);
            }
            //
            a.To      = To;
            a.From    = From;
            a.CC      = CC;
            a.BCC     = BCC;
            a.Subject = Subject;
            //
            ibp = a;
            //
            flds = ibp.Fields;
            flds["urn:schemas:mailheader:Content-Type"].Value  = "multipart/signed; protocol=application/pkcs7-signature; micalg=SHA1";
            flds["urn:schemas:mailheader:thread-index"].Value  = "";
            flds["urn:schemas:mailheader:thread-topic"].Value  = "";
            flds["urn:schemas:mailheader:priority"].Value      = "";
            flds["urn:schemas:mailheader:importance"].Value    = "";
            flds["urn:schemas:mailheader:content-class"].Value = "";
            flds["urn:schemas:mailheader:X-Priority"].Value    = 1;
            flds.Update();

            // Setup the first body part; this is the header
            // plus the file contents.
            ibp2  = ibp.AddBodyPart(1);
            flds1 = ibp2.Fields;
            flds1["urn:schemas:mailheader:content-class"].Value = "urn:content-classes:message";
            if (PlainText)
            {
                flds1["urn:schemas:mailheader:importance"].Value   = Important;
                flds1["urn:schemas:mailheader:content-type"].Value = "text/plain";
            }
            else
            {
                flds1["urn:schemas:mailheader:content-type"].Value     = "text/html; charset=UTF-8";
                flds1["urn:schemas:httpmail:content-media-type"].Value = "text/html";
                flds1["urn:schemas:httpmail:importance"].Value         = Important;
            }
            flds1["urn:schemas:mailheader:content-transfer-encoding"].Value = "7bit";
            flds1.Update();

            a.MimeFormatted = true;
            //
            // If HTML, put the HTML body in ...
            if (!PlainText)
            {
                Body = HTMLBody;
            }
            //
            string messageToSign = Body;

            //
            ADODB.Stream stm;
            stm      = ibp2.GetDecodedContentStream();
            stm.Type = ADODB.StreamTypeEnum.adTypeText;
            stm.WriteText(messageToSign, ADODB.StreamWriteEnum.adWriteChar);
            stm.Flush();
            //
            // Pass in the full stream (header and content) and sign it.
            string strbase64 = SignEMail(ibp2.GetStream().ReadText(ibp2.GetStream().Size), Encoding.UTF8);

            //string strbase64 = this.Body; // SignEMail(ibp2.GetStream().ReadText(ibp2.GetStream().Size), Encoding.UTF8);
            //
            if (strbase64 == "error")
            {
                Result = "Error: Could not Sign it?";
                return(false);
            }
            //
            // Can add an attachment here, but it then shows the "Digital Signature" as an attachment
            //a.AddAttachment("C:\\Test.txt", "", "");
            //
            ibp2  = a.AddBodyPart(2);
            flds2 = ibp2.Fields;
            flds2["urn:schemas:mailheader:content-Disposition"].Value       = "attachment; FileName=smime.p7s";
            flds2["urn:schemas:mailheader:content-Description"].Value       = "S/MIME Cryptographic Signature";
            flds2["urn:schemas:mailheader:Content-Type"].Value              = "application/x-pkcs7-signature; Name=smime.p7s";
            flds2["urn:schemas:mailheader:Content-Transfer-Encoding"].Value = "base64";
            flds2.Update();
            //
            stm      = ibp2.GetEncodedContentStream();
            stm.Type = ADODB.StreamTypeEnum.adTypeText;
            stm.WriteText(strbase64, ADODB.StreamWriteEnum.adWriteLine);
            stm.Flush();
            stm.Close();
            //
            a.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value             = CdoSendUsing.cdoSendUsingPort;
            a.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value            = SMTPServer;
            a.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value        = SMTPPort;
            a.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"].Value = TimeOut;
            a.Configuration.Fields.Update();
            //
            a.Send();
            //
            // Get the whole SMIME message.
            Result = a.GetStream().ReadText(a.GetStream().Size);
            //
            if (Debug)
            {
                Console.WriteLine("\n{0}\n", Result);
            }
            //
            return(true);
        }
Example #4
0
        static void Main(string[] args)
        {
            #region 获取包含所有日志链接的HTML文本
            //string baseQueryUrl = "http://www.douban.com/people/oranjeruud/notes?start=";
            //for (int i = 0; i < 23; i++)
            //{
            //    string queryUrl = baseQueryUrl + (i * 10);
            //    HttpWebRequest httpWebRequest = HttpWebRequest.CreateHttp(queryUrl);
            //    httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95";
            //    HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();//取得响应
            //    if (httpWebResponse.StatusCode.Equals(HttpStatusCode.OK))//若响应状态码为200,说明成功,可以分析得到的数据
            //    {
            //        StreamReader reader = new StreamReader(new BufferedStream(httpWebResponse.GetResponseStream(), 4 * 200 * 1024));
            //        GetBlogLink(reader.ReadToEnd());
            //        reader.Close();
            //    }
            //    Thread.Sleep(3000);
            //}
            #endregion

            #region 根据获得的日志链接获取日志网页和mht文件
            Message msg = new CDO.MessageClass();
            CDO.Configuration c = new CDO.ConfigurationClass();
            msg.Configuration = c;
            StreamReader reader = new StreamReader("links.txt");
            int i = 0;
            while (!reader.EndOfStream)
            {
                i++;
                string link = reader.ReadLine();
                HttpWebRequest httpWebRequest = HttpWebRequest.CreateHttp(link);
                httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95";
                HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();//取得响应
                if (httpWebResponse.StatusCode.Equals(HttpStatusCode.OK))//若响应状态码为200,说明成功,可以分析得到的数据
                {
                    StreamReader httpReader = new StreamReader(new BufferedStream(httpWebResponse.GetResponseStream(), 4 * 200 * 1024));
                    string htmlContent = httpReader.ReadToEnd();
                    httpReader.Close();
                    string title = GetBlogTitle(htmlContent);
                    #region 保存为html文件
                    StreamWriter writer = new StreamWriter(i + ".html");
                    writer.Write(htmlContent);
                    writer.Close();
                    #endregion
                    #region 保存为mht文件
                    //msg.HTMLBody = htmlContent;
                    msg.CreateMHTMLBody(link, CDO.CdoMHTMLFlags.cdoSuppressNone, "", "");
                    ADODB.Stream stream = msg.GetStream();
                    stream.SaveToFile(title + ".mht", ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
                    #endregion
                }
                if (i == 1) break;
            }
            reader.Close();
            #endregion
        }