Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //download.ashx
- using LumiSoft.Net.Mail;
- using LumiSoft.Net.MIME;
- using LumiSoft.Net.POP3.Client;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace Mojna.WebApplication
- {
- public class downloader : IHttpHandler
- {
- public void ProcessRequest(HttpContext context)
- {
- HttpResponse Response = context.Response;
- HttpRequest Request = context.Request;
- Response.Clear();
- //dosya isteği gelmişse işle
- if (!string.IsNullOrEmpty(Request["DosyaAdi"]))
- {
- byte[] data = null;
- popaBaglan(Request, ref data);
- Response.AddHeader("content-disposition", "attachment; filename=" + Request["DosyaAdi"]);
- Response.OutputStream.Write(data, 0, data.Length);
- }
- //her şekilde responsu bitir.
- Response.End();
- }
- void popaBaglan(HttpRequest Request, ref byte[] data)
- {
- POP3_Client clt = new POP3_Client();
- clt.Connect("sunucu", 110, false);
- clt.Authenticate("mail", "parola", true);
- clt.Timeout = int.MaxValue;
- //mesajı bul
- var mesaj = clt.Messages.OfType<POP3_ClientMessage>().First(p => p.UID == Request["MesajID"]);
- //mesajı parsele
- Mail_Message mime = Mail_Message.ParseFromByte(mesaj.MessageToByte());
- //dosyayı bul
- MIME_Entity entry = mime.Attachments.First(p => p.ContentType.Param_Name == Request["DosyaAdi"]);
- //dosyayı data olarak al ve ref ile geri dön.
- string FileName = entry.ContentType.Param_Name;
- data = ((MIME_b_SinglepartBase)entry.Body).Data;
- }
- public bool IsReusable
- {
- get
- {
- return false;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment