public Form1() { InitializeComponent(); int i; for (i = 0; i < 10; i++) { tb_index[i] = new TabPage(); mailList[i] = new RecvMail(); } Thread receiverThread = new Thread(receiveMails); receiverThread.IsBackground = true; receiverThread.Start(); msgBoxDelegate = new updateMsgBoxD(updateMsgBoxMethod); }
static int keySize = 128; // can be 192 or 128 or 256 public Form1() { InitializeComponent(); int i; for (i = 0; i < 10; i++) { tb_index[i] = new TabPage(); mailList[i] = new RecvMail(); } Thread receiverThread = new Thread(receiveMails); receiverThread.IsBackground = true; receiverThread.Start(); msgBoxDelegate = new updateMsgBoxD(updateMsgBoxMethod); }
private void receiveMails() { string redirector = "10.108.7.138"; string sreq; byte[] req = new byte[1024]; byte[] resp = new byte[10240]; string sresp; int port = 8002; System.Text.Encoding enc = System.Text.Encoding.ASCII; IPHostEntry IPhst = Dns.GetHostEntry(redirector); IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], port); while (true) { Socket s = new Socket(endPt.AddressFamily, SocketType.Stream, ProtocolType.Tcp); Console.WriteLine("connecting to redirector.........."); s.Connect(endPt); Console.WriteLine("Connected to redirector!!!"); // send the offset sreq = "" + offset; sreq = RijndaelSimple.Encrypt(sreq, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize); req = Convert.FromBase64String(sreq); s.Send(req, 0, req.Length, SocketFlags.None); //req = enc.GetBytes(sreq); //s.Send(req); // get number of mails to receive sresp = getResponse64(s); int mailToRecv = Int32.Parse(sresp); sreq = "" + 1; sreq = RijndaelSimple.Encrypt(sreq, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize); req = Convert.FromBase64String(sreq); s.Send(req, 0, req.Length, SocketFlags.None); //req = enc.GetBytes(sreq); //s.Send(req); RecvMail[] tmpMailList = new RecvMail[10]; int i, j; for (i = 0; i < mailToRecv; i++) { sresp = getResponse64(s); // parse and store msg in a list char[] separator = new char[1]; separator[0] = '\n'; string[] lines = sresp.Split(separator); tmpMailList[i] = new RecvMail(); tmpMailList[i].mailNo = Int32.Parse(lines[0]); tmpMailList[i].from = lines[1]; tmpMailList[i].fromMail = lines[2]; tmpMailList[i].subject = lines[3]; tmpMailList[i].dateTimeInfo = lines[4]; //MessageBox.Show(lines[4] + "\n" + lines[5]); tmpMailList[i].attachmentCount = Int32.Parse(lines[5]); tmpMailList[i].attachments = null; tmpMailList[i].attachments = new string[tmpMailList[i].attachmentCount]; for (j = 1; j < tmpMailList[i].attachmentCount; j++) { tmpMailList[i].attachments[j] = lines[5 + j]; } tmpMailList[i].body = ""; for (j = 5 + tmpMailList[i].attachmentCount; j < lines.Length; j++) tmpMailList[i].body = tmpMailList[i].body + "\n" + lines[j]; //MessageBox.Show(sresp); sreq = "" + 1; sreq = RijndaelSimple.Encrypt(sreq, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize); req = Convert.FromBase64String(sreq); s.Send(req, 0, req.Length, SocketFlags.None); //req = enc.GetBytes(sreq); //s.Send(req); } // copy temp list to global list for(i=0; i<mailToRecv; i++) mailList[i] = tmpMailList[i]; mailInList = mailToRecv; //string msg = "get new msgs again??"; //MessageBox.Show(msg); // display updated list msgList.Clear(); //msgBox.Items.Clear(); for (i = 0; i < mailInList; i++) { string elem = mailList[i].from + "-" + mailList[i].subject; //MessageBox.Show(elem); msgList.Add((string)elem); //msgBox.Items.Add(elem); } //msgBox.Items. this.msgBox.Invoke(this.msgBoxDelegate); Thread.Sleep(20000); } }
private void receiveMails() { string redirector = "10.108.7.138"; string sreq; byte[] req = new byte[1024]; byte[] resp = new byte[10240]; string sresp; int port = 8002; System.Text.Encoding enc = System.Text.Encoding.ASCII; IPHostEntry IPhst = Dns.GetHostEntry(redirector); IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], port); while (true) { Socket s = new Socket(endPt.AddressFamily, SocketType.Stream, ProtocolType.Tcp); Console.WriteLine("connecting to redirector.........."); s.Connect(endPt); Console.WriteLine("Connected to redirector!!!"); // send the offset sreq = "" + offset; sreq = RijndaelSimple.Encrypt(sreq, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize); req = Convert.FromBase64String(sreq); s.Send(req, 0, req.Length, SocketFlags.None); //req = enc.GetBytes(sreq); //s.Send(req); // get number of mails to receive sresp = getResponse64(s); int mailToRecv = Int32.Parse(sresp); sreq = "" + 1; sreq = RijndaelSimple.Encrypt(sreq, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize); req = Convert.FromBase64String(sreq); s.Send(req, 0, req.Length, SocketFlags.None); //req = enc.GetBytes(sreq); //s.Send(req); RecvMail[] tmpMailList = new RecvMail[10]; int i, j; for (i = 0; i < mailToRecv; i++) { sresp = getResponse64(s); // parse and store msg in a list char[] separator = new char[1]; separator[0] = '\n'; string[] lines = sresp.Split(separator); tmpMailList[i] = new RecvMail(); tmpMailList[i].mailNo = Int32.Parse(lines[0]); tmpMailList[i].from = lines[1]; tmpMailList[i].fromMail = lines[2]; tmpMailList[i].subject = lines[3]; tmpMailList[i].dateTimeInfo = lines[4]; //MessageBox.Show(lines[4] + "\n" + lines[5]); tmpMailList[i].attachmentCount = Int32.Parse(lines[5]); tmpMailList[i].attachments = null; tmpMailList[i].attachments = new string[tmpMailList[i].attachmentCount]; for (j = 1; j < tmpMailList[i].attachmentCount; j++) { tmpMailList[i].attachments[j] = lines[5 + j]; } tmpMailList[i].body = ""; for (j = 5 + tmpMailList[i].attachmentCount; j < lines.Length; j++) { tmpMailList[i].body = tmpMailList[i].body + "\n" + lines[j]; } //MessageBox.Show(sresp); sreq = "" + 1; sreq = RijndaelSimple.Encrypt(sreq, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize); req = Convert.FromBase64String(sreq); s.Send(req, 0, req.Length, SocketFlags.None); //req = enc.GetBytes(sreq); //s.Send(req); } // copy temp list to global list for (i = 0; i < mailToRecv; i++) { mailList[i] = tmpMailList[i]; } mailInList = mailToRecv; //string msg = "get new msgs again??"; //MessageBox.Show(msg); // display updated list msgList.Clear(); //msgBox.Items.Clear(); for (i = 0; i < mailInList; i++) { string elem = mailList[i].from + "-" + mailList[i].subject; //MessageBox.Show(elem); msgList.Add((string)elem); //msgBox.Items.Add(elem); } //msgBox.Items. this.msgBox.Invoke(this.msgBoxDelegate); Thread.Sleep(20000); } }