-
Notifications
You must be signed in to change notification settings - Fork 5
/
mms-to-sms
executable file
·60 lines (49 loc) · 1.36 KB
/
mms-to-sms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/perl
use strict;
use warnings;
my $mmsDir = "$ENV{HOME}/Code/n9/backup/backup-mms/msg";
my $smsDir = "$ENV{HOME}/Code/n9/backup/backup-sms";
sub getSms($);
sub main(@){
my @msgDirs = `ls -t -1 $mmsDir`;
chomp foreach @msgDirs;
my @sms;
for my $msgDir(@msgDirs){
my $sms = getSms $msgDir;
if(defined $sms){
push @sms, $sms;
}
}
my $timestamp = `date +%Y_%m_%d-%s`;
chomp $timestamp;
my $smsFile = "$smsDir/mms-$timestamp.sms";
my $count = @sms;
print "writing $count fake SMS to $smsFile\n";
open FH, "> $smsFile" or die "Could not write to $smsFile\n";
print FH @sms;
close FH;
}
sub getSms($){
my $msgDir = shift;
my @textFiles = `ls $mmsDir/$msgDir/*.txt 2>/dev/null`;
chomp foreach @textFiles;
@textFiles = grep {-f $_} @textFiles;
my $headerFile = "$mmsDir/$msgDir/header";
if(-f $headerFile){
my $header = `cat $headerFile`;
my $from = $1 if $header =~ /^message-from=(.*)$/m;
my $date = $1 if $header =~ /^message-timestamp=(.*)$/m;
$date = $date =~ /^(\d+)$/ ? $1 : undef;
my $dateFmt = `date --date \@$date '+%Y-%m-%d %H:%M:%S'`;
chomp $dateFmt;
my $msg = "";
$msg = `cat @textFiles` if @textFiles > 0;
$msg =~ s/"/""/g;
$msg = "\"$msg\"";
if(defined $date and defined $from){
return "$from,1,$dateFmt,$msg\n";
}
}
return undef;
}
&main(@ARGV);