Making cloud using email. Decode base64 in sections for SRAM issue?

I am using arduino.cc/Code/Email to send the emails which include .csv excell files, and am using Code/WiFiPOP3EmailClient to read emails, and base 64 decoding library to decode the .csv files.

I have this part working. The problem I am having is that I don't know how to separate the base64 encoded part that come in from the email, so that I can decode sections at a time. I need to do this so SRAM doesn't run out. Is this possible? I can't afford to store 64 characters on my current SRAM.

Is the cloud system idea a failure, or can I separate base64 and run it through the decoding process in sections?

Base 64 encodes six bits per character. Four characters will get you 24 bits which is three bytes. You can decode each four character chunk of input to get three character of decoded output.

Can you show me how?

This is the serial readout

--------------Boundary-00=_WIRNYO0VMPBCI7WDN0JI
Content-Type: application/vnd.ms-excel
Content-Disposition: attachment; filename=TEST.CSV
Content-Transfer-Encoding: base64

SGksSGVsbG8sNzgNCjEwMywoODg4KSAzMzMtODg4OCxvcmFuZ2UNCiwscGl6emENCnVubyxt
ZWdhLGR1bw0KLCwNCjg4LDg5LDEwMA0K

--------------Boundary-00=_WIRNYO0VMPBCI7WDN0JI--

Because code is so long, I can't include the decoding part in same message. I am using GitHub - adamvr/arduino-base64: A base64 library for the arduino platform, written in C to decode base64, but I can't decode it on my main sketch because I don't have the SRAM, so I need to break it down in sections. Below is code that pulls the file from my email that is encoded in base64.

byte getEmail()
    {
      byte thisByte = 0;
      byte respCode;
      char rtnVal[64];
      int mailCount,mailSize;
      char tBuf[64];
     
      if(client.connect(server,port) == 1) {
        Serial.println(F("connected"));
      } else {
        client.stop();
        Serial.println(F("connection failed"));
        return 0;
      }
     
      if(!eRcv()) return 0;
      Serial.println(rtnBuf);
     
      Serial.println(F("Sending User"));
      strcpy_P(tBuf,PSTR("USER "));
      strcat(tBuf,userName);
      strcat_P(tBuf,PSTR("\r\n"));
      client.write(tBuf);
      if(!eRcv()) return 0;
      Serial.println(rtnBuf);
     
      Serial.println(F("Sending Password"));
      strcpy_P(tBuf,PSTR("PASS "));
      strcat(tBuf,passWord);
      strcat_P(tBuf,PSTR("\r\n"));
      client.write(tBuf);
      if(!eRcv()) return 0;
      Serial.println(rtnBuf);
     
      Serial.println(F("Sending STAT"));
      strcpy_P(tBuf,PSTR("STAT\r\n"));
      client.write(tBuf);
      if(!eRcv()) return 0;
      Serial.println(rtnBuf);
     
      sscanf(rtnBuf,"%s %u %u",rtnVal,&mailCount,&mailSize);
      Serial.print(F("mail count: "));
      Serial.println(mailCount);
     
      for(int i = 1;i<=mailCount;i++) {
        strcpy_P(tBuf,PSTR("RETR "));
        itoa(i,rtnBuf,10);
        strcat(tBuf,rtnBuf);
        strcat(tBuf,"\r\n");
        client.write(tBuf);
        if(ePrint() == 2) {
          strcpy(tBuf,"DELE ");      
          itoa(i,rtnBuf,10);
          strcat(tBuf,rtnBuf);
          strcat(tBuf,"\r\n");
          client.write(tBuf);
     
          if(!eRcv) Serial.println("Not deleted");
          else Serial.println("Deleted");
        }
     
        Serial.println(F("\r\nEND"));
      }
     
      Serial.println(F("Sending QUIT"));
      strcpy_P(tBuf,PSTR("QUIT\r\n"));
      client.write(tBuf);
      if(!eRcv()) return 0;
      Serial.println(rtnBuf);
     
      client.stop();
     
      Serial.println(F("disconnected"));
     
      return 1;
    }
     
     
     
    byte eRcv()
    {
      byte respCode;
      byte thisByte;
      int loopCount = 0;
      byte rtnCount = 0;
     
      while(!client.available()) {
        delay(1);
        loopCount++;
     
        // if nothing received for 10 seconds, timeout
        if(loopCount > 10000) {
          client.stop();
          Serial.println(F("\r\nTimeout"));
          return 0;
        }
      }
     
      while(client.available())
      {
        thisByte = client.read();  
    //    Serial.write(thisByte);
        if(rtnCount < 99) {
          rtnBuf[rtnCount]=thisByte;
          rtnCount++;
          rtnBuf[rtnCount]=0;
        }
      }
     
      if(rtnBuf[0] == '-') return 0;
     
      return 1;
    }
     
    byte ePrint()
    {
      byte respCode;
      byte thisByte;
      int loopCount = 0;
      byte rtnCount = 0;
      byte lineLength = 0;
      bool endMsg = false;
      bool msgBody = false;
      bool forArduino = false;
      char lineBuf[64];
      byte pinNo;
      char pinState[8];
     
      while(!client.available()) {
        delay(1);
        loopCount++;
     
        // if nothing received for 10 seconds, timeout
        if(loopCount > 10000) {
          client.stop();
          Serial.println(F("\r\nTimeout"));
          return 0;
        }
      }
     
      while(!endMsg) {
        while(client.available())
        {
          thisByte = client.read();  
          // if it is for the Arduino and past the header
          if(forArduino && msgBody) Serial.write(thisByte);
          
     
          if(thisByte == '\n') {
            // end of line      
            if(strlen(lineBuf) == 0) {
              if(!msgBody) Serial.println("Message body");
              msgBody = true;
            }
            if(strcmp(lineBuf,".") == 0) {
              // end of message
              endMsg = true;
            }
            if(!msgBody && (strncmp(lineBuf,"From:",5) == 0)) {
              // from
              Serial.println(lineBuf);
            }
            if(!msgBody && (strncmp(lineBuf,"Subject:",8) == 0)) {
              // subject
              Serial.print(F("lineBuf is "));
              Serial.println(lineBuf);
              if(strcmp(&lineBuf[9],subjectLine) == 0) {
                Serial.println("On Arduino!===========================================================================================");
                forArduino= true;
                digitalWrite(33,HIGH);
              }
            }
            if(!msgBody && (strncmp(lineBuf,"Subject:",8) == 0)) {
              // subject
              Serial.print(F("lineBuf2 is "));
              Serial.println(lineBuf);
              Serial.println(lineBuf);
              if(strcmp(&lineBuf[9],subjectLine2) == 0) {
                Serial.println("Off Arduino!=============================================================================================");
                forArduino= true;
                digitalWrite(33,LOW);
              }
            }
     
            if(msgBody && strncmp(lineBuf,"on",2) == 0) {
              Serial.print("Command! D");        
              sscanf(lineBuf,"%*s %u %s",&pinNo,pinState);
              Serial.print(pinNo);
              Serial.print(" ");
              Serial.println(pinState);
              digitalWrite(33,HIGH);
              //Responce();
     //SendR=HIGH;
              //if(strcmp(pinState,"on") == 0) digitalWrite(pinNo,HIGH);        
              //if(strcmp(pinState,"off") == 0) digitalWrite(pinNo,LOW);        
            }
            if(msgBody && strncmp(lineBuf,"off",3) == 0) {
              Serial.print("Command! D");        
              sscanf(lineBuf,"%*s %u %s",&pinNo,pinState);
              Serial.print(pinNo);
              Serial.print(" ");
              Serial.println(pinState);
              digitalWrite(33,LOW);
     
              if(strcmp(pinState,"on") == 0) digitalWrite(pinNo,HIGH);        
              if(strcmp(pinState,"off") == 0) digitalWrite(pinNo,LOW);        
            }
     
            lineLength = 0;
            lineBuf[0] = 0;
          }
          else if(thisByte != '\r') {
            // another character
            if(lineLength < 63) {
              lineBuf[lineLength] = thisByte;
              lineLength++;
              lineBuf[lineLength] = 0;
            }
     
          }
        }
        }
     
      if(forArduino) return 2;
      return 1;
    }
     
    void efail()
    {
      byte thisByte = 0;
      int loopCount = 0;
     
      client.println("QUIT");
     
      while(!client.available()) {
        delay(1);
        loopCount++;
     
        // if nothing received for 10 seconds, timeout
        if(loopCount > 10000) {
          client.stop();
          Serial.println(F("\r\nTimeout"));
          return;
        }
      }
     
      while(client.available())
      {
        thisByte = client.read();  
        Serial.write(thisByte);
      }
     
      client.stop();
     
      Serial.println(F("disconnected"));
    }

I am curious are attachments more secure to send in email, than in plain text? I don't understand why they would encrypt the attachments, but not the email text itself? And if they use standard base64 encryption, is it a more secure than not encrypting it at all?

The attachments are encoded so that they are not limited to ascii characters. That way they can include images or any other sort of data. It is not intended to provide security.

There is an official document that defines the standard which can be downloaded.

...R

There is an official document that defines the standard which can be downloaded.

https://www.ietf.org/rfc/rfc2045.txt (+ 2046, 2047, 2048, 2049 )

latest - https://www.ietf.org/rfc/rfc4648.txt