This is my G-mail




package midletehs8sms; /** * * @author Morten */ public class G_mail { MidletEHS8SMS parent; NetworkRegistration networkregistration; Notify_Incoming_Messages nim; Process_Message pm; Reader reader; Subrutine subrutine; String_Manipulation sm; boolean g_mail_troubled = false; boolean in_transparent_mode = false; int result = 0; int loop = 0; int mmail_loop = 0; int mmail_result = 0; int mmail_delay = 0; int gmail_loop = 0; int gmail_result = 0; int gmail_delay = 0; String atcmdresponse = null; String cr_array[] = null; String comma_array[] = null; // ---------------------------------------------------------------------------- public static final int g_id = 1; // 0..9 public static final String g_conid = "1"; //0..5 public static final String g_apn = null; public static final String g_auth = "1"; // 0-1 ? public static final String g_subject = "Testing my Gemalto EHS6" ; public static final String g_servtype = "smtp"; public static final String g_server = "smtp.gmail.com"; public static final String g_from = "user@gmail.com"; public static final String g_to = "someone"; public static final String g_username = "user@gmail.com"; public static final String g_password = "password"; public static final String g_address = "smtps://"+g_username+":"+g_password+"@"+g_server+""; // ---------------------------------------------------------------------------- public void G_mail( MidletEHS8SMS parent ,Process_Message pm ,Subrutine subrutine ,NetworkRegistration networkregistration ,String_Manipulation sm //--------------------------------------------------------- ){ //--------------------------------------------------------- //--------------------------------------------------------- this.parent = parent; this.pm = pm; this.subrutine = subrutine; this.networkregistration = networkregistration; this.sm=sm; //--------------------------------------------------------- /*****************************************************************************/ }//Internet_Service_Commands /*****************************************************************************/ // System.out.println(""); /*****************************************************************************/ /*****************************************************************************/ // AT^SISI Internet Service Information /*****************************************************************************/ /*****************************************************************************/ public int AT_QUERY_SISI(int id){ // System.out.println("Here start AT_QUERY_SISI Internet Service Information"); // ---------------------------------------------------------------------------- int ServiceState = 0; int pointer = 0; String just_a_try; /*--------------------------- AT^SISI? --------------------------------------*/ try{ /*--------------------------- AT^SISI? --------------------------------------*/ atcmdresponse = new String(); try{ atcmdresponse = parent.SendCommand("AT^SISI="+id+" \r"); // System.out.println("AT_QUERY_SISI = "+atcmdresponse); }catch (Exception in) { System.out.println("Exception in AT^SISI?"); return -1; } /*--------------------------- AT^SISI? --------------------------------------*/ // AT^SISI? // ^SISI: 0,2,0,0,0,0 // ^SISI: 1,"Smtp" // OK // Internet service state. // 2: The service is not opened, but ready for configuration. // 3: Connecting State after opening a service with AT^SISO where the // connection is being established. // 4: Up The SMTP service will not enter <srvState>=4 until the host // has written the first data packet with AT^SISW. // 5: Closing Internet Service is closing the network connection. // 6: Down // 7: Alerting // A client tries to connect to the Transparent TCP Listener service. // 8: Connected // A client is connected with the Transparent TCP Listener service. // 9: Released // The client has disconnected from the Transparent TCP Listener // service but there are unread data. // To go back into Up/Listening state read the pending data using // AT^SIST or discard them by using AT^SISH. // AT^SIST=<srvProfileId> // AT^SISH=<srvProfileId>, <mode> // [0] Socket is closed with graceful option // 1 Socket is closed without graceful option // ---------------------------------------------------------------------------- if(atcmdresponse.indexOf("+CME ERROR") != -1){ System.out.println("Return -1"); return -1;} /*--------------------------- AT^SISI? --------------------------------------*/ try{ cr_array = parent.sm.Split_String_Into_Array('\r', atcmdresponse); /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ for(int i = 0; i < cr_array.length; i++){ // System.out.println("CR_ARRAY["+i+"] in SISI = " + cr_array[i]); if(cr_array[i].trim().indexOf("SISI:".trim()) != -1){ pointer = i; break; } } // System.out.println("Pointer in SISI = " + pointer); /*--------------------------- AT^SISI? --------------------------------------*/ }catch (Exception in) { System.out.println("Exception in AT^SISI Split String with CR"); return -1; } /*--------------------------- AT^SISI? --------------------------------------*/ if( (cr_array != null) && (cr_array.length > 1) && (cr_array[0] != null) && (cr_array[0].indexOf("AT^SISI") != -1) && (cr_array[pointer] != null) && (cr_array[pointer].indexOf("SISI:") != -1) ){ // System.out.println("CR_ARRAY["+pointer+"] = " + cr_array[pointer]); /*--------------------------- AT^SISI? --------------------------------------*/ try{ String substring = sm.Get_Substring(':', cr_array[pointer].trim()); comma_array = sm.Split_String_Into_Array(',', substring); /*--------------------------- AT^SISI? --------------------------------------*/ /* for(int i = 0; i < comma_array.length; i++){ System.out.println("Comma-array["+i+"] = " + comma_array[i]);} /*--------------------------- AT^SISI? --------------------------------------*/ if(comma_array.length < 5) return -1; ServiceState = Integer.parseInt(comma_array[1].trim()); // System.out.println("ServiceState(SISI) = " + ServiceState ); if(ServiceState == 9) { /*--------------------------- AT^SISI? --------------------------------------*/ try{ /*--------------------------- AT^SISI? --------------------------------------*/ atcmdresponse = parent.SendCommand("AT^SIST="+id+" \r"); in_transparent_mode = true; parent.Delay(500); /*--------------------------- AT^SISI? --------------------------------------*/ }catch (Exception in) { System.out.println("Exception in AT^SISI?"); return -1; } /*--------------------------- AT^SISI? --------------------------------------*/ }//if(ServiceState == 9) /*--------------------------- AT^SISI? --------------------------------------*/ }catch (NumberFormatException in) { System.out.println("NumberFormatException in AT_QUERY_SISI "+in); return -1; } /*--------------------------- AT^SISI? --------------------------------------*/ }//indexOf("SISI:") else{ return -1;} /*--------------------------- AT^SISI? --------------------------------------*/ }catch (Exception in) { System.out.println("Exception in AT^SISI = " + in); return -1; } /*--------------------------- AT^SISI? --------------------------------------*/ return ServiceState; /*--------------------------- AT^SISI? --------------------------------------*/ }//END /*****************************************************************************/ /***********************END OF AT_QUERY_SISI *********************************/ /*****************************************************************************/ // System.out.println(""); /*****************************************************************************/ /*****************************************************************************/ // Information: Internet Service Error Report /*****************************************************************************/ /*****************************************************************************/ public String AT_SISE(int srvProfileId){ // ---------------------------------------------------------------------------- // AT^SISE Internet Service Error Report // ---------------------------------------------------------------------------- try{ // ---------------------------------------------------------------------------- System.out.println(""); atcmdresponse = parent. SendCommand("AT^SISE=" + srvProfileId + " \r"); // System.out.println("Response -> " + atcmdresponse); // ---------------------------------------------------------------------------- }catch (Exception in) { System.out.println("ATCommandFailedException " + in); System.out.println(" "); parent.exception = true; } // ---------------------------------------------------------------------------- return atcmdresponse; } /*****************************************************************************/ /*****************************************************************************/ // End of InternetServiceErrorReport /*****************************************************************************/ /*****************************************************************************/ // System.out.println(""); /*****************************************************************************/ /*****************************************************************************/ // Sending G-Mail using Internet Service Commands /*****************************************************************************/ /*****************************************************************************/ public boolean Send_Gmail(String message){ g_mail_troubled = false; /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ try{ /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ atcmdresponse = parent.SendCommand("at+cmee=2 \r"); System.out.println("Response -> " + atcmdresponse); while(true){ parent.nwr.GetShortNetworkRegistration(); if(parent.registered) break; parent.Delay(500); } System.out.println("GetShortNetworkRegistration() " + parent.registered); /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ //conType: mandatory System.out.println("Clears the connection profile. "); atcmdresponse = parent.SendCommand("AT^SISC="+g_id+" \r"); System.out.println("Response -> " + atcmdresponse); //----------------------------------------------------------------------------- if(atcmdresponse.indexOf("+CME") != -1) this.g_mail_troubled=true; /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ //conType: mandatory atcmdresponse = parent.SendCommand("AT^SICS="+g_id+",conType,\"GPRS0\" \r"); System.out.println("Response -> " + atcmdresponse); //----------------------------------------------------------------------------- if(atcmdresponse.indexOf("+CME") != -1) this.g_mail_troubled=true; /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ //srvType: mandatory atcmdresponse = parent.SendCommand("AT^SISS="+g_id+",srvType,\"" + g_servtype + "\" \r"); System.out.println("Response -> " + atcmdresponse); //----------------------------------------------------------------------------- if(atcmdresponse.indexOf("+CME") != -1) this.g_mail_troubled=true; /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ //apn: mandatory /* atcmdresponse = parent.SendCommand("AT^SICS="+g_id+",apn,\""+g_apn+"\" \r"); System.out.println("Response -> " + atcmdresponse); //----------------------------------------------------------------------------- if(atcmdresponse.indexOf("+CME") != -1) this.g_mail_troubled=true; /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ //conId: mandatory atcmdresponse = parent.SendCommand("AT^SISS="+g_id+",conId,\"" + g_conid + "\"\r"); System.out.println("Response -> " + atcmdresponse); //----------------------------------------------------------------------------- if(atcmdresponse.indexOf("+CME") != -1) this.g_mail_troubled=true; /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ //address: mandatory atcmdresponse = parent.SendCommand("AT^SISS="+g_id+",address, \""+ g_address +"\" \r"); System.out.println("Response -> " + atcmdresponse); //----------------------------------------------------------------------------- if(atcmdresponse.indexOf("+CME") != -1) this.g_mail_troubled=true; /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ //smFrom: mandatory atcmdresponse = parent.SendCommand("AT^SISS="+g_id+",smFrom, \"" + g_from + "\" \r"); System.out.println("Response -> " + atcmdresponse); //----------------------------------------------------------------------------- if(atcmdresponse.indexOf("+CME") != -1) this.g_mail_troubled=true; /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ //smRcpt: mandatory atcmdresponse = parent.SendCommand("AT^SISS="+g_id+",smRcpt, \"" + g_to + "\" \r"); System.out.println("Response -> " + atcmdresponse); //----------------------------------------------------------------------------- if(atcmdresponse.indexOf("+CME") != -1) this.g_mail_troubled=true; /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ //smSubj: optional atcmdresponse = parent.SendCommand("AT^SISS="+g_id+",smSubj, \"" + g_subject + "\" \r"); System.out.println("Response -> " + atcmdresponse); //----------------------------------------------------------------------------- if(atcmdresponse.indexOf("+CME") != -1) this.g_mail_troubled=true; /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ //smAuth: optional atcmdresponse = parent.SendCommand("AT^SISS="+g_id+",smAuth, \"" + g_auth + "\" \r"); System.out.println("Response -> " + atcmdresponse); //----------------------------------------------------------------------------- if(atcmdresponse.indexOf("+CME") != -1) this.g_mail_troubled=true; /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ //smMsg: optional atcmdresponse = parent.SendCommand("AT^SISS=" + g_id + ",smMsg,\"" + message + "\"\r"); System.out.println("Response -> " + atcmdresponse); //----------------------------------------------------------------------------- if(atcmdresponse.indexOf("+CME") != -1) this.g_mail_troubled=true; /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ //AT^SISO=0 Internet Service Open System.out.println("Now open the connection."); atcmdresponse = parent.SendCommand("AT^SISO=" + g_id + " \r"); parent.Delay(500); System.out.println("Response -> " + atcmdresponse); /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ if(atcmdresponse.indexOf("+CME") != -1){ this.g_mail_troubled=true; System.out.println("Error in Internet Service Open -> " + this.AT_SISE(g_id)); } /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ gmail_result = 0; gmail_loop =60; gmail_delay = 1000; /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ gmail_result = this.AT_QUERY_SISI(g_id); System.out.println("G-Mail Response Open -> " + gmail_result); System.out.println("G-Mail Loop = " + gmail_loop); System.out.println("G-Mail Delay = " + gmail_delay); while(gmail_loop > 0){ gmail_result = this.AT_QUERY_SISI(g_id); if(gmail_result == 4) break; parent.Delay(gmail_delay); gmail_loop--; }//while System.out.println("G-Mail Response Open -> " + gmail_result); System.out.println("G-Mail Remaining LOOP*s = " + gmail_loop); /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ gmail_loop =60; gmail_delay = 1000; /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ System.out.println("G-Mail Loop = " + gmail_loop); System.out.println("G-Mail Delay = " + gmail_delay); if(gmail_result == 4){ System.out.println("G-Mail Waiting to close"); while(gmail_loop > 0){ gmail_result = this.AT_QUERY_SISI(g_id); if(gmail_result != 4) break; parent.Delay(gmail_delay); gmail_loop--; }//while }//if(gmail_result == 4) System.out.println("G-Mail Response close = " + this.AT_QUERY_SISI(g_id)); System.out.println("G-Mail Remaining LOOP*s = " + gmail_loop); if(in_transparent_mode){ try{ //AT^SISH Internet Listener Service Disconnect //Socket is closed with graceful option atcmdresponse = parent.SendCommand("AT^SISH="+g_id+",0 \r"); parent.Delay(1000); }catch (Exception in) { System.out.println("Exception in Listener Service Disconnect"); } }//if(g_mail_troubled) /* ------------------------------------------------------------------------- */ /* DISCONNECTING */ /* ------------------------------------------------------------------------- */ atcmdresponse = parent.SendCommand("AT^SISC="+g_id+"\r"); System.out.println("Response -> " + atcmdresponse); System.out.println("G-Mail Response close if any: " + this.AT_SISE(g_id)); /* ------------------------------------------------------------------------- */ /* -------------------------- Sending_Gmail -------------------------------- */ /* ------------------------------------------------------------------------- */ }catch (Exception in) { System.out.println("Exception in Sending Gmail " + in); System.out.println("Exception in Sending Gmail " + this.AT_SISE(g_id)); return false;} //------------------------------------- return !this.g_mail_troubled; }//END OF Sending_Gmail /*****************************************************************************/ /*****************************************************************************/ /* Sending_Gmail */ /*****************************************************************************/ /*****************************************************************************/ // System.out.println(""); /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ }