I wanted to share a small script I wrote for those who know how to use it. It converts non-binary pim-backup message files to html files.
Usage: ruby <file> <message_file>
Code:
#-sms2html----------------------------------------------------------------#
# ChaosR (<[email protected]>) wrote this file. As long as #
# you do not touch this note and keep this note here you can do whatever #
# you want with this stuff. Also, the author(s) are not responsible for #
# whatever happens using this. #
#-------------------------------------------------------------------------#
require 'jcode' if RUBY_VERSION[0..2] == "1.8"
class SMSConverter
attr_accessor :messages, :raw, :by_folder, :by_name, :by_number
SPEC = [
:msg_id,
:sender_name,
:sender_address,
:sender_address_type,
:prefix,
:subject,
:body,
:body_type,
:folder,
:account,
:msg_class,
:content_length,
:msg_size,
:msg_flags,
:msg_status,
:modify_time,
:delivery_time,
:recipient_nbr,
:recipients,
:attachment_nbr,
:attachments
]
RECIP_SPEC = [
:id,
:name,
:phone,
:var1,
:var2,
:type
]
FOLDERS = {
"\\%MDF1" => "INBOX",
"\\%MDF2" => "OUTBOX",
"\\%MDF3" => "SENT",
"\\%MDF4" => "TRASH",
"\\%MDF5" => "DRAFTS"
}
def initialize(file)
f = File.open(file)
@raw = f.read
f.close
raw2array
clean_messages
sort_messages
end
def raw2array
messages = []
state = { :arg => 0, :escaped => false, :in_string => false }
sms = {}
@raw.each_char do |byte|
arg = SPEC[state[:arg]]
sms[arg] = "" unless sms[arg]
if byte == "\0" or byte == "\r"
next
elsif state[:escaped]
sms[arg] << byte
state[:escaped] = false
elsif state[:in_string]
if byte == "\""
state[:in_string] = false
elsif byte == "\\"
state[:escaped] = true
else
sms[arg] << byte
end
elsif byte == "\\"
state[:escaped] = true
elsif byte == "\""
state[:in_string] = true
elsif byte == ";"
state[:arg] += 1
elsif byte == "\n"
raise "Faulty conversion or corrupt file" if state[:escaped] or state[:in_string] or state[:arg] != 20
messages << sms
sms = {}
state[:arg] = 0
else
sms[arg] << byte
end
end
@messages = messages
end
def clean_messages
@messages.map! do |sms|
sms[:modify_time] = Time.local( *sms[:modify_time].split(",") )
unless sms[:delivery_time] == ""
sms[:delivery_time] = Time.local( *sms[:delivery_time].split(",") )
else
sms[:delivery_time] = sms[:modify_time]
end
sms[:recipient_nbr] = sms[:recipient_nbr].to_i
sms[:body_type] = sms[:body_type].to_i
sms[:msg_flags] = sms[:msg_flags].to_i
sms[:msg_status] = sms[:msg_status].to_i
sms[:attachment_nbr] = sms[:attachment_nbr].to_i
sms[:content_length] = sms[:content_length].to_i
sms[:msg_size] = sms[:msg_size].to_i
sms[:folder] = FOLDERS[sms[:folder]]
if sms[:recipient_nbr] > 0
recipients = {}
sms[:recipients].split(";").each_with_index { |var, index| recipients[RECIP_SPEC[index]] = var }
recipients[:id] = recipients[:id].to_i
recipients[:var1] = recipients[:var1].to_i
recipients[:var2] = recipients[:var2].to_i
sms[:recipients] = recipients
end
sms
end
end
def sort_messages
@messages = @messages.sort { |a, b| a[:delivery_time] <=> b[:delivery_time] }
@by_folder = {}
@messages.each do |sms|
@by_folder[sms[:folder]] = [] unless @by_folder[sms[:folder]]
@by_folder[sms[:folder]] << sms
end
@by_name = {}
@messages.each do |sms|
if sms[:recipient_nbr] > 0
if sms[:recipients][:name] != ""
name = sms[:recipients][:name]
else
name = sms[:recipients][:phone]
end
else
if sms[:sender_name] != ""
name = sms[:sender_name]
else
name = get_number_from_address(sms[:sender_address])
end
end
@by_name[name] = [] unless @by_name[name]
@by_name[name] << sms
end
@by_number = {}
@messages.each do |sms|
if sms[:recipient_nbr] > 0
name = sms[:recipients][:phone]
else
name = get_number_from_address(sms[:sender_address])
end
@by_number[name] = [] unless @by_number[name]
@by_number[name] << sms
end
end
def get_number_from_address(address)
if address =~ /^(\+?\d+)$/
return address
elsif address =~ /\<(\+?\d+)\>/
return $1
else
return false
end
end
end
if $0 == __FILE__
require 'fileutils'
dir = "./messages"
my_name = "yourname"
sms = SMSConverter.new(ARGV[0])
FileUtils.mkdir_p(dir)
sms.by_name.each { |name, messages|
filename = File.join(dir, "#{name}.html")
f = File.open(filename, "w")
f << "<html><body>"
messages.each { |sms|
sent = sms[:recipient_nbr] > 0
message = sms[:subject]
f << "<b>--- #{sent ? my_name : name} (#{sms[:delivery_time].strftime("%H:%M:%S, %a %d-%b-%Y")}) ---</b><br/>"
f << "<pre>#{message.strip}</pre><br/><br/>"
}
f << "</body></html>"
f.close
}
end
I'm a little new to this, but am really interested.
I installed Ruby and then created your ruby script. I then run from command prompt:
convertsms.rb pim.vol convertedsms.htm
but I get the following error. What have I done wrong?
C:\Users\mjt\Desktop>convertsms.rb pim.vol convertedsms.htm
C:/Users/mjt/Desktop/convertsms.rb:67:in `raw2array': undefined method `each_cha
r' for #<String:0x24ee9d4> (NoMethodError)
from C:/Users/mjt/Desktop/convertsms.rb:57:in `initialize'
from C:/Users/mjt/Desktop/convertsms.rb:199:in `new'
from C:/Users/mjt/Desktop/convertsms.rb:199
I'm just supposed to run it on a copy of my pim.vol correct?
Thanks!
You have to install pimbackup on your phone, make a non-binary backup. Download the backup to your computer, unzip it, and run this script on the msgs_<date>.csm file. This script will then create a folder called messages and store all the messages per user in it.
ChaosR said:
You have to install pimbackup on your phone, make a non-binary backup. Download the backup to your computer, unzip it, and run this script on the msgs_<date>.csm file. This script will then create a folder called messages and store all the messages per user in it.
Click to expand...
Click to collapse
Ok, I installed pim backup backed up the messages, copied the file to my computer, extracted the csm file and the following happened when I tried to run it.
C:\Users\mjt\Desktop>ruby convertsms.rb msgs.csm
convertsms.rb:67:in `raw2array': undefined method `each_char' for #<String:0x33e
94c> (NoMethodError)
from convertsms.rb:57:in `initialize'
from convertsms.rb:199:in `new'
from convertsms.rb:199
Thanks!
Heh, it seems on Windows you need to include jcode for each_char to work. Put the new code in. Cheers.
how to convert the binary backup to a non binary backup? other than restoring and backing up.
Relaying SMS
Would it be possible to relay the SMS to another phone when backing up, perhaps as a transfer operation, or by sending SMS via a webservice?
Related
For the program I posted here, I want to handle incoming calls before the default popup appears (to replace the ringtone).
Currently, my tool seems to be quick enough without lineSetAppPriority in most cases, but sadly not in all...
I was using the following code: (currently removed again, because it didn't work and even caused some troubles...)
Initialization:
Code:
if ( lineInitialize( &LineApp, theApp.m_hInstance, LineCallback,
theApp.m_pszAppName, &LineHandleCount ) == 0 )
{
LineHandles = new HLINE[LineHandleCount];
for(DWORD i = 0; i < LineHandleCount; i++)
{
if ( lineNegotiateAPIVersion( LineApp, i, 0x00010000, 0x00020000,
&ver, &extensionID ) == 0 )
{
rc = lineOpen( LineApp, i, &LineHandles[i], ver, 0, (DWORD)this,
LINECALLPRIVILEGE_MONITOR|LINECALLPRIVILEGE_OWNER,
LINEMEDIAMODE_INTERACTIVEVOICE, NULL );
if ( rc < 0 )
LineHandles[i] = NULL;
else
if ( LineHandleSignal == NULL )
LineHandleSignal = LineHandles[i];
}
}
HRESULT res = lineSetAppPriority( theApp.m_pszAppName,
LINEMEDIAMODE_INTERACTIVEVOICE,
NULL,
LINEREQUESTMODE_MAKECALL,
NULL, 1 );
}
Callback:
Code:
VOID FAR PASCAL LineCallback( DWORD hDevice,
DWORD dwMsg,
DWORD dwCallbackInstance,
DWORD dwParam1,
DWORD dwParam2,
DWORD dwParam3
)
{
if ( dwMsg == LINE_CALLSTATE )
{
LINECALLINFO *callInfo = (LINECALLINFO *)calloc(sizeof(LINECALLINFO)
+1024, 1);
callInfo->dwTotalSize = sizeof(LINECALLINFO)+1024;
lineGetCallInfo( (HCALL)hDevice, callInfo );
// different stuff...
HRESULT res;
// Remove from priority list, so lineHandoff will run the default
// call window
res = lineSetAppPriority( theApp.m_pszAppName,
LINEMEDIAMODE_INTERACTIVEVOICE, NULL,
LINEREQUESTMODE_MEDIACALL, NULL, 0 );
// Forward event to next instance (usually Windows' phone app)
lineHandoff( (HCALL)hDevice, NULL, callInfo->dwMediaMode );
// Set to top priority again
res = lineSetAppPriority( theApp.m_pszAppName,
LINEMEDIAMODE_INTERACTIVEVOICE, NULL,
LINEREQUESTMODE_MEDIACALL, NULL, 1 );
}
lineSetAppPriorty returns OK in all cases. But when a call comes in, the
default bubble applears simultaneously with the callback function. I
wanted it to be shown when I do the lineHandoff...
What am I doing wrong?
TIA,
Mirko
I used lineSetAppPriority too, with same result....
I think there is one way.....kill cprog
Hi All,
Is anyone familiar with the EDB notification mechanism? I have some code that has opened the appointments database to get change notifications, all well and good. The trouble is I am unable to delete the CENOTIFICATION structure, meaning I get a memory leak after every change.
if anyone has seen this or knows the solution, I'd be grateful.
Code:
CEOID apps_oid;
request= new CENOTIFYREQUEST; // or (CENOTIFYREQUEST *) LocalAlloc (LPTR,
// sizeof (CENOTIFYREQUEST));
if (request) {
request->dwSize = sizeof (CENOTIFYREQUEST);
request->hwnd = hwnd;
request->hHeap = NULL;
request->dwFlags = CEDB_EXNOTIFICATION;
request->dwParam = param;
database = CeOpenDatabaseInSession ( NULL,
&pim_guid,
&apps_oid,
L"Appointments Database",
0,
0, // or CEDB_AUTOINCREMENT,
request);
}
. . .
case WM_DBNOTIFICATION:
{
CENOTIFICATION * notification = (CENOTIFICATION *)lParam;
// Always returns FALSE
BOOL hr = CeFreeNotification(request, notification);
// Always returns 5 - access denied
DWORD dw = GetLastError();
}
break;
Hi,
I have write an application for the HD2 to take a photo in my application.
But the photo has always a resolution of 640x480 even if I set
ccd.Resolution = new Size(2592, 1552);
My code:
Code:
public void OpenCamera(CameraCaptureMode mode)
{
DateTime timestamp = DateTime.Now;
CameraCaptureDialog ccd = new CameraCaptureDialog();
ccd.InitialDirectory = Config.GetString("UserImageFolder");
if (!System.IO.Directory.Exists(ccd.InitialDirectory))
System.IO.Directory.CreateDirectory(ccd.InitialDirectory);
ccd.Mode = mode;
ccd.StillQuality = CameraCaptureStillQuality.High;
ccd.Resolution = new Size(2592, 1552);
String basename = String.Format("{0:0000}-{1:00}-{2:00} {3:00}{4:00}{5:00} - ", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
if (Global.SelectedCache != null)
{
basename += Global.RemoveInvalidFatChars(StringUtils.Left(Global.SelectedCache.Name, 32).Trim());
ccd.Title = Global.SelectedCache.Name;
}
String extension = (mode == CameraCaptureMode.Still) ? ".jpg" : ".mp4";
int cnt = 0;
while (System.IO.File.Exists(Config.GetString("UserImageFolder") + "\\" + basename + ((cnt > 0) ? " - " + cnt.ToString() : "") + extension))
cnt++;
ccd.DefaultFileName = basename + ((cnt > 0) ? " - " + cnt.ToString() : "") + extension;
try
{
ccd.ShowDialog();
String name = (Global.SelectedCache != null) ? Global.SelectedCache.Name : "Image";
AnnotateMedia(name, ccd.DefaultFileName, Global.Locator.LastValidPosition, timestamp);
}
catch (Exception exc)
{
#if DEBUG
Global.AddLog("Main.OpenCamera: " + exc.ToString());
#endif
MessageBox.Show("An error occured! Seems as if your device had no camera!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
cameraImageButton.Enabled = false;
cameraVideoButton.Enabled = false;
}
ccd.Dispose();
}
Is anybody out here, who can tell me what I have to do, to change the resolution to the max. (2592x1552) of the HD2?
Thanks a lot and please sorry my bad english.
Andreas
I found the solution
CameraCaptureDialog accept only resolution that define in the registry.
So I modify
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Pictures\Camera\OEM\PictureResolution\1]
the keys
Height = 1944
Width = 2592
No I can take pictures with 2592x1552 with the code modify
Code:
ccd.Resolution = new Size(2592, 1552);
Hi!
Can you help me, please? I'm working on an Android app. I get some characters from a file on the Internet and put it to a TextView. These characters are ASCII characters. Then I read these characters one by one and convert it to numbers with the following code:
Code:
char my_char2;
char my_char3;
int myNum = 0;
for (int k = 170; k < len; k++) {
if (c.charAt(k) == '0' && c.charAt(k+1) == '.') {
my_char2 = c.charAt(k+13);
my_char3 = c.charAt(k+14);
myNum = my_char2 * 256 + my_char3;
}
}
Then I write it to an another TextView:
Code:
crlNumber.setText("" + myNum);
The problem is that this can only convert standard ASCII characters(from 0 to 127) except of the new line character(character number 10), carriage return character(character number 13) and the cancel character(character number 24).
But I need to convert also the extended ASCII characters(from 128 to 255) and the 3 characters mentioned above.
What should I do?
Thanks for helping.
Do these help?
http://stackoverflow.com/questions/13826781/java-extended-ascii-table-usage
http://stackoverflow.com/questions/5535988/string-to-binary-and-vice-versa-extended-ascii
nikwen said:
Do these help?
http://stackoverflow.com/questions/13826781/java-extended-ascii-table-usage
http://stackoverflow.com/questions/5535988/string-to-binary-and-vice-versa-extended-ascii
Click to expand...
Click to collapse
A little. I have tried the following code below. It didn't show me the number of the extended ascii characters. But I think I should somehow read the text not as a String, but as a byte, and then I think, it should work(maybe I am wrong). If it is right, please, can you tell me, how should I do it?
Code:
final String textSource = "path to my file";
URL textUrl;
try {
textUrl = new URL(textSource);
BufferedReader bufferReader = new BufferedReader(
new InputStreamReader(textUrl.openStream()));
String StringBuffer;
String stringText = "";
while ((StringBuffer = bufferReader.readLine()) != null) {
stringText += StringBuffer;
}
bufferReader.close();
textMsg.setText(stringText);
String PT = textMsg.getText().toString();
CharSequence c = new String(PT);
String string0 = "";
String string1 = "";
char my_char2;
char my_char3;
String binary = "";
String binary2 = "";
int myNum2 = 0;
int decimalValue1 = 0;
int decimalValue2 = 0;
for (int k = 170; k < len; k++) {
if (c.charAt(k) == '0' && c.charAt(k+1) == '.') {
my_char2 = c.charAt(k+13);
my_char3 = c.charAt(k+14);
string0 = Character.toString(my_char2);
string1 = Character.toString(my_char3);
char[] buffer = string0.toCharArray();
byte[] b = new byte[buffer.length];
for (int i = 0; i < b.length; i++) {
b[i] = (byte) buffer[i];
binary = Integer,toBinaryString(b[i] & 0xFF);
decimalValue1 = Integer.parseInt(binary, 2);
}
char[] buffer2 = string1.toCharArray();
byte[] b2 = new byte[buffer2.length];
for (int i = 0; i < b2.length; i++) {
b2[i] = (byte) buffer2[i];
binary2 = Integer.toBinaryString(b2[i] & 0xFF);
decimalValue2 = Integer.parseInt(binary2, 2);
}
myNum2 = decimalValue1 * 256 + decimalValue2;
}
}
crlNumber.setText("" + binary2 + "," + decimalValue1 + "," + decimalValue2 + "," + myNum2);
}
adamhala007 said:
A little. I have tried the following code below. It didn't show me the number of the extended ascii characters. But I think I should somehow read the text not as a String, but as a byte, and then I think, it should work(maybe I am wrong). If it is right, please, can you tell me, how should I do it?
Code:
final String textSource = "path to my file";
URL textUrl;
try {
textUrl = new URL(textSource);
BufferedReader bufferReader = new BufferedReader(
new InputStreamReader(textUrl.openStream()));
String StringBuffer;
String stringText = "";
while ((StringBuffer = bufferReader.readLine()) != null) {
stringText += StringBuffer;
}
bufferReader.close();
textMsg.setText(stringText);
String PT = textMsg.getText().toString();
CharSequence c = new String(PT);
String string0 = "";
String string1 = "";
char my_char2;
char my_char3;
String binary = "";
String binary2 = "";
int myNum2 = 0;
int decimalValue1 = 0;
int decimalValue2 = 0;
for (int k = 170; k < len; k++) {
if (c.charAt(k) == '0' && c.charAt(k+1) == '.') {
my_char2 = c.charAt(k+13);
my_char3 = c.charAt(k+14);
string0 = Character.toString(my_char2);
string1 = Character.toString(my_char3);
char[] buffer = string0.toCharArray();
byte[] b = new byte[buffer.length];
for (int i = 0; i < b.length; i++) {
b[i] = (byte) buffer[i];
binary = Integer,toBinaryString(b[i] & 0xFF);
decimalValue1 = Integer.parseInt(binary, 2);
}
char[] buffer2 = string1.toCharArray();
byte[] b2 = new byte[buffer2.length];
for (int i = 0; i < b2.length; i++) {
b2[i] = (byte) buffer2[i];
binary2 = Integer.toBinaryString(b2[i] & 0xFF);
decimalValue2 = Integer.parseInt(binary2, 2);
}
myNum2 = decimalValue1 * 256 + decimalValue2;
}
}
crlNumber.setText("" + binary2 + "," + decimalValue1 + "," + decimalValue2 + "," + myNum2);
}
Click to expand...
Click to collapse
Hm, I don't know. According to this answer, you can change the encoding on the desktop, otherwise you will just see question marks.
But according to the accepted answer here, this should be done automatically on a Linux system. And Android is Linux based. Did you try it on an Android device or just on your computer?
Bytes shouldn't work. In Java they are signed, so their range is -128 ... 127.
nikwen said:
Hm, I don't know. According to this answer, you can change the encoding on the desktop, otherwise you will just see question marks.
But according to the accepted answer here, this should be done automatically on a Linux system. And Android is Linux based. Did you try it on an Android device or just on your computer?
Bytes shouldn't work. In Java they are signed, so their range is -128 ... 127.
Click to expand...
Click to collapse
Yes, I tried it on my Android device. Maybe, the best choice would be then to use that certificate code which you suggested me in one of my previous threads, but the problem is, that I am beginner in Android developing and I read it and I didn't know how to use it in my code. So I thougt, if I got the 2 ASCII characters and converted it to decimal numbers, it would also work. And it also works until I have the standard ASCII characters. When there is an extended ASCII character, it shows me the number 65533.
adamhala007 said:
Yes, I tried it on my Android device. Maybe, the best choice would be then to use that certificate code which you suggested me in one of my previous threads, but the problem is, that I am beginner in Android developing and I read it and I didn't know how to use it in my code. So I thougt, if I got the 2 ASCII characters and converted it to decimal numbers, it would also work. And it also works until I have the standard ASCII characters. When there is an extended ASCII character, it shows me the number 65533.
Click to expand...
Click to collapse
But I think I have found out something.
Code:
string0 = Character.toString(my_char2);
string1 = Character.toString(my_char3);
int one = 0;
int two = 0;
String ascii1="\u001f";
String ascii2="\u0018";
String aa = "";
String bb = "";
if(string0.equals(ascii1)){
one = one + 31;
aa = aa + one;
}else{
one = 1;
}
if(string1.equals(ascii2)){
two = two + 24;
bb = bb + two;
}else{
two = 1;
}
textPrompt.setText("" + aa + bb);
But this needs a little correction, because this way it doesn't show me anything, but if I write
Code:
textPrompt.setText("" + aa);
inside my first if statement it shows me correctly 31. What can be the mistake I have made?
convert ASCII character
I'm a self android learner. I want to convert ascii code to character. Here is the code I used.
String s = "1000001";
int num = Integer.parseInt(s, 2);
TextView textView = new TextView(this);
textView.setText(String.valueOf(num));
setContentView(textView);
Here s is 1000001(65 in decimal) 65 is ascii value of 'A'. I want to get 'A' in my output screen.variable num has the value 65. please help me
When I use json_encode($response), it returns only the first row of the query, how to make it return all the rows?
main.php
Code:
$email = $_POST['email'];
$password = $_POST['password'];
$user = $db->getUserByEmailAndPassword($email, $password);
if ($user != false ) {
// user found
$response["error"] = FALSE;
$response["user"]["name"] = $user["name"];
$response["user"]["email"] = $user["email"];
$response["user"]["dega"] = $user["dega"];
$response["user"]["salla"] = $user["salla"];
$response["user"]["ora"] = $user["ora"];
$response["user"]["lenda"] = $user["lenda"];
$response["user"]["dita"] = $user["dita"];
echo json_encode($response);
}
method.php
Code:
public function getUserByEmailAndPassword($email, $password) {
$result = mysql_query("SELECT U.name, U.email, U.password, F.dega,
O.salla, O.ora, O.lenda, O.dita FROM users U
INNER JOIN fakulteti F on U.id = F.studenti
INNER JOIN orari O on F.id = O.fakulteti WHERE email = '$email'") or die(mysql_error());
$no_of_rows = mysql_num_rows($result);
if ($no_of_rows > 0) {
$result = mysql_fetch_array($result);
$encrypted_password = $result['password']
if ($encrypted_password == $password) {
return $result;
}
}
}
Android class and this is how I recieve a response on my android:
Code:
JSONObject user = jObj.getJSONObject("user");
String name = user.getString("name");
String email = user.getString("email");
String dega = user.getString("dega");
String salla = user.getString("salla");
String ora = user.getString("ora");
String lenda = user.getString("lenda");
String dita = user.getString("dita");
bump!!!!