To work with Sprint's smtp.sprintpcs.com server, I had to add some base64 encoding algorithms to SendNote. For those that are interested, here is some Java J2ME CDLC MIDP 1.0 code for converting a string into base64.
[code:1:4f812c5721]import java.util.*;
public class MiniBase64 {
private MiniBase64() {}
protected static final byte[] base64Chars = {
'A','B','C','D','E','F','G','H',
'I','J','K','L','M','N','O','P',
'Q','R','S','T','U','V','W','X',
'Y','Z','a','b','c','d','e','f',
'g','h','i','j','k','l','m','n',
'o','p','q','r','s','t','u','v',
'w','x','y','z','0','1','2','3',
'4','5','6','7','8','9','+','/',
};
protected static final int Sextet0 = 0x3F000000;
protected static final int Sextet1 = 0x00FC0000;
protected static final int Sextet2 = 0x0003F000;
protected static final int Sextet3 = 0x00000FC0;
protected static final int Sextet4 = 0x0000003F;
protected static final int Sextet0Offset = 24;
protected static final int Sextet1Offset = 18;
protected static final int Sextet2Offset = 12;
protected static final int Sextet3Offset = 6;
protected static final int Sextet4Offset = 0;
protected static final int Octet0Offset = 24;
protected static final int Octet1Offset = 16;
protected static final int Octet2Offset = 8;
protected static final int Octet3Offset = 0;
private static byte[] intToSextets(int reg) {
byte[] out = new byte[4];
out[0] = (byte)((reg & Sextet1) >>> Sextet1Offset);
out[1] = (byte)((reg & Sextet2) >>> Sextet2Offset);
out[2] = (byte)((reg & Sextet3) >>> Sextet3Offset);
out[3] = (byte)(reg & Sextet4);
return(out);
}
private static int bytesToInt(byte[] in) {
int reg = 0;
reg = (in[0] << Octet1Offset) + (in[1] << Octet2Offset) + in[2];
return(reg);
}
private static byte[] bytesToSextets(byte[] in) {
return(intToSextets(bytesToInt(in)));
}
private static int roundUp(int in, int factor) {
int out = in;
int mod;
mod = in % factor;
if (mod != 0) {
out = out + factor - mod;
}
return(out);
}
private static byte[] pickThree(byte[] array, int index) {
byte[] out = {0,0,0};
System.arraycopy(array, index, out, 0, Math.min(array.length - index, 3));
return(out);
}
private static byte[] translate(byte[] in) {
byte[] out = new byte[in.length];
int index;
for (index = 0; index < out.length; index++) {
out[index] = base64Chars[in[index]];
}
return(out);
}
public static byte[] encode(byte[] in) {
byte[] out = new byte[roundUp(in.length,3)*4/3];
int indexIn = 0;
int indexOut = 0;
for (indexIn = 0; indexIn < in.length; indexIn = indexIn+3) {
byte[] outQuad = translate(bytesToSextets(pickThree(in, indexIn)));
indexOut = indexIn*4/3;
System.arraycopy(outQuad, 0, out, indexOut, outQuad.length);
}
indexOut = in.length*4/3+1;
while(indexOut < out.length) {
out[indexOut] = '=';
indexOut++;
}
return(out);
}
public static String encode(String string) {
return new String(encode(string.getBytes()));
}
}
[/code:1:4f812c5721]