my own SMTP client - memory issue??

Hi, I'm trying to develop my own simple SMTP client code with error-handling.
I've got a mailserver running to test on. I'm also using the 28J60 with UIpethernet lib

Problem is that after a few succesfull client.read's the arduino receives 4-5 characters incorrect. I'm suspecting a memory issue.

Below snapshot of my code:

byte emailstatus=1;
char* clientreplies[]={"helo www.arduino.be","auth login","Z3JlZW5lcmd5bWFpbHRlc3RAZ3JlZW5lcmd5bWFpbHRlc3QuYmU=","U3V6dWtp","mail from:wouter@arduino.be"};
char* serverreplies[]={"220","250","334","334","235"};
String response="";


void loop()
{
   // if there are incoming bytes available 
  // from the server, read them and print them:
  //Serial.write(client.available());
  if (client.available()) {            
    char c = client.read();
    Serial.print(c);
    response+=c;
    if (c == '\n'){
      //Serial.println("end of line signal received");
      //Serial.print("Response string: ");
      if (response.substring(0,3) == serverreplies[emailstatus-1] && emailstatus<=5) {
        client.println(clientreplies[emailstatus-1]);
        Serial.println(clientreplies[emailstatus-1]);
        //Serial.println(response.length());
        //delay(1000);
        response="";            //reset response string
        emailstatus+=1;
      }
                                      
      
      }
  }

  // as long as there are bytes in the serial queue,
  // read them and send them out the socket if it's open:
  //Serial.println(Serial.available());
  while (Serial.available() > 0) {
    /*char inChar = Serial.read();
    if (client.connected()) {
      client.print(inChar);
      Serial.print(inChar);
     //client.println("");
    //client.println(""); 
    }*/
   // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    // do nothing:
    while(true);
  }
}
}

Serial monitor result:

My IP address: 192.168.0.233.connecting...
connected
220 www.greenergysolutions.be ESMTP
helo www.arduino.be
250 Hello.
auth login
334 VXNlcm5hbWU6
Z3JlZW5lcmd5bWFpbHRlc3RAZ3JlZW5lcmd5bWFpbHRlc3QuYmU=
@ à @  zc3dvcmQ6

this "@ à @ " is wrong, I couldn't even copy-paste it to here for some reason. It should be again "334....". Characters starting from zc3... are again correct though

Ideas anyone?

Ideas anyone?

The usual one. Quit using the String class.

Can this string class have anything to do with it?
the replies from the server on the serial monitor handled one char at a time...

the replies from the server on the serial monitor handled one char at a time...

"Handled" how? They are "handled" by appending then to a String. Look at the += operator function in the WString.cpp file to see how memory is fragmented when adding one character at a time to a String.

Problem is that after a few succesfull client.read's the arduino receives 4-5 characters incorrect. I'm suspecting a memory issue.

You don't show your full code, but if you think you are having intermittent memory issues, then put any static text in your code in F() macros.

Hi Paul and zoomkat, thank you for your feedback.
By saying 'one char at a time', I mean the output sent on the serial monitor; since I'm printing to serial monitor every char seperately when it comes in before appending it to a string.

The string stuff I use only for error checking. For testing I disabled all error checking so I'm no longer using strings in my whole program. Problem persists.

I've pointed out the problem a bit further, and it appear that the lenght of the client reply (between 52 and 58 characters) disturbs the correct processing of the next server reply. It sounds very strange and I think it's a problem with uipethernet library.

I've posted further details in the thread of uipethernet:
http://forum.arduino.cc/index.php?topic=178024.180

Update: Problem is solved, there was -as suspected- a problem with the 28J60. Norbert has send me 'bugfix' library and everything looks normal now. More details on link from my previous post.