Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- ssl = new System.Net.Security.SslStream(tcpc.GetStream());
- ssl.AuthenticateAsClient("imap.gmail.com");
- receiveResponse("");
- //Console.WriteLine("username : "); //<- antiguas lineas de la version consola, omito siguientes
- //username = Console.ReadLine();
- username = "MIusuario";
- password = "complicada";
- receiveResponse("$ LOGIN " + username + " " + password + " rn");//<- comandaos al servidor, entiendo yo
- receiveResponse("$ LIST " + """" + " "*"" + "rn");
- receiveResponse("$ SELECT INBOXrn");
- receiveResponse("$ STATUS INBOX (MESSAGES)rn");
- //Console.WriteLine("enter the email number to fetch :");
- //int number = int.Parse(Console.ReadLine()); //<- pedia el numero de mail
- int number = 1; //<- le pongo uno a martillo,
- receiveResponse("$ FETCH " + number + " body[header]rn");//<- le pide cabeza de ese mail
- receiveResponse("$ FETCH " + number + " body[text]rn");//<- le pide cuerpo de ese mail
- receiveResponse("$ LOGOUTrn"); //<- desconecta
- }
- catch (Exception ex)
- {
- //Console.WriteLine("error: " + ex.Message);
- Program.Form1.RichOut("error: " + ex.Message);
- }
- finally
- {
- if (ssl != null)
- {
- ssl.Close();
- ssl.Dispose();
- }
- if (tcpc != null)
- {
- tcpc.Close();
- }
- }
- //Console.ReadKey();
- }
- static void receiveResponse(string command)
- {
- Program.Form1.RichOut("Comando: " + command); //<- mi trace de comandos
- try
- {
- if (command != "")
- {
- if (tcpc.Connected)
- {
- dummy = Encoding.ASCII.GetBytes(command);//<-pasa estring a matriz de chars
- ssl.Write(dummy, 0, dummy.Length);
- Program.Form1.RichOut("DUMMYS:" + UTF8Encoding.ASCII.GetString(dummy));
- }
- else
- {
- throw new ApplicationException("TCP CONNECTION DISCONNECTED");
- }
- }
- Program.Form1.RichOut("ReadTimeout = " + Convert.ToString(ssl.ReadTimeout));
- ssl.ReadTimeout = 100000; // <- le subo el timeout, NO va
- Program.Form1.RichOut("ReadTimeout = " + Convert.ToString(ssl.ReadTimeout));
- buffer = new byte[8003];
- for (int k = 0; k < 8003; k++) { buffer[k] = 0; } //<- borro previo, TAMPOCO
- System.Threading.Thread.Sleep(1000);//<- le meto retardo antes de leer, TAMPOCO
- //ssl.Flush(); //<- estaba en la version original, sin esto falla igualmente.
- bytes = ssl.Read(buffer, 0, 8000); ////////////// <<<<<<<<------------- AQUI FALLA, se corta inesperadamente, bastante repetible el fallo
- //bytes = letras leidas, y es cierto, a pesar del fallo, devuelve las leidas reales, que luego muestra.
- //buffer[20] = 0; //<- CON ESTO SIMULO EL FALLO
- Program.Form1.RichOut("Convert.ToString(bytes) = " + Convert.ToString(bytes));
- //for (int k = 0; k < bytes + 22; k++) { if (buffer[k] == 0) { buffer[k] = 32; }; }//<- incluso trato de filtrar los 0s
- sb.Append(Encoding.ASCII.GetString(buffer));
- //Program.Form1.RichOut("TEST 1:" + ASCIIEncoding.Unicode.GetString(buffer)); //<- me rompo cabeza si eran distintas codificaciones
- //Program.Form1.RichOut("TEST 2:" + UnicodeEncoding.Unicode.GetString(buffer));
- //Program.Form1.RichOut("TEST 3:" + UTF8Encoding.Unicode.GetString(buffer));
- //Program.Form1.RichOut("rnrnTEST 01:" + ASCIIEncoding.UTF7.GetString(buffer));//<- alguna HASTA TRADUCE AL CHINO,,,
- Program.Form1.RichOut("rnrnTEST 23:" + UTF8Encoding.ASCII.GetString(buffer));//<- esta parece aceptable
- //for (int k = 0; k < bytes+22; k++) { Program.Form1.RichOut(Convert.ToString(Convert.ToChar(buffer[k])) + " " + Convert.ToString(Convert.ToInt16(buffer[k])) ); }
- //display de cada byte del bufer. se detiene antes de leer el 0.
- }
- catch (Exception ex)
- {
- //Program.Form1.RichOut("trace 13");
- throw new ApplicationException(ex.Message);
- }
- }
- }
Add Comment
Please, Sign In to add comment