Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Adding PIN message sending feature #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

import net.rim.blackberry.api.mail.Address;
import net.rim.blackberry.api.mail.AddressException;
import net.rim.blackberry.api.mail.Message;
import net.rim.blackberry.api.mail.Folder;
import net.rim.blackberry.api.mail.Message;
import net.rim.blackberry.api.mail.PINAddress;
import net.rim.blackberry.api.mail.Store;

/**
Expand Down Expand Up @@ -312,12 +313,42 @@ public static Address[] stringToAddresses( String addressString ) {

for( int i = 0; i < emails.length; i++ ) {
try {
addresses[ i ] = new Address( emails[ i ], emails[ i ] );
// Check if PIN address, use PINAddress instead of Address
if(MessageUtility.isPIN (emails[i])){
addresses[ i ] = new PINAddress( emails[ i ], emails[ i ]);
} else {
addresses[ i ] = new Address( emails[ i ], emails[ i ] );
}
} catch( AddressException e ) {
addresses[ i ] = null;
}
}

return addresses;
}

/**
* Check whether the address given is PIN address.
* PIN Address is in hexadecimal format [ 0-9, A-F ]
*
* @param address address to be check
* @return true when the address is a PIN address
*/
public static boolean isPIN ( String address ) {
char[] check = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

// PIN should in 8 length string
if(address.length()!=8) return false;
for(int i=0;i<address.length();i++){
boolean pass = false;
for(int j=0;j<check.length;j++){
if(address.charAt(i)==check[j]){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering if you had considered an algorithm comparing ASCII codes ( for fewer comparisons) or regular expressions?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. I have considered that. Since I don't need to compare all characters I not prefer to use regex at all.
Well thanks for the information about the IICL. I'll review the document. Thanks

pass = true;
break;
}
}
if(!pass) return false;
}
return true;
}
}