1 #include "../helper/locales.h"
12 #include "../helper/formats.h"
13 #include "../helper/cmdline.h"
15 #include "../helper/message-display.h"
16 #include "../helper/printing.h"
17 #include "../helper/string.h"
19 void BackupSMS(int argc UNUSED
, char *argv
[])
22 GSM_SMS_Backup Backup
;
23 GSM_MultiSMSMessage sms
;
24 GSM_SMSFolders folders
;
25 gboolean BackupFromFolder
[GSM_MAX_SMS_FOLDERS
];
26 gboolean start
= TRUE
;
27 gboolean DeleteAfter
= FALSE
, askdelete
= TRUE
;
31 if (strcasecmp(argv
[3],"-yes") == 0) {
32 always_answer_yes
= TRUE
;
34 if (strcasecmp(argv
[3],"-all") == 0) {
35 always_answer_yes
= TRUE
;
44 sms
.SMS
[0].Location
= 0;
47 error
=GSM_GetSMSFolders(gsm
, &folders
);
51 DeleteAfter
= answer_yes("%s", _("Delete each sms after backup?"));
54 for (j
=0;j
<folders
.Number
;j
++) {
55 BackupFromFolder
[j
] = FALSE
;
56 if (answer_yes(_("Backup sms from folder \"%s\"%s?"),
57 DecodeUnicodeConsole(folders
.Folder
[j
].Name
),
58 folders
.Folder
[j
].Memory
== MEM_SM
? _(" (SIM)") : ""
60 BackupFromFolder
[j
] = TRUE
;
63 while (error
== ERR_NONE
) {
64 sms
.SMS
[0].Folder
=0x00;
65 error
=GSM_GetNextSMS(gsm
, &sms
, start
);
71 for (j
=0;j
<sms
.Number
;j
++) {
72 if (BackupFromFolder
[sms
.SMS
[j
].Folder
-1]) {
73 switch (sms
.SMS
[j
].PDU
) {
74 case SMS_Status_Report
:
78 if (sms
.SMS
[j
].Length
== 0) break;
79 if (smsnum
< GSM_BACKUP_MAX_SMS
) {
80 Backup
.SMS
[smsnum
] = malloc(sizeof(GSM_SMSMessage
));
81 if (Backup
.SMS
[smsnum
] == NULL
) Print_Error(ERR_MOREMEMORY
);
82 Backup
.SMS
[smsnum
+ 1] = NULL
;
84 printf(_(" Increase %s\n") , "GSM_BACKUP_MAX_SMS");
88 *Backup
.SMS
[smsnum
] = sms
.SMS
[j
];
98 error
= GSM_AddSMSBackupFile(argv
[2],&Backup
);
102 for (j
=0;j
<smsnum
;j
++) {
103 Backup
.SMS
[j
]->Folder
= 0;
104 error
=GSM_DeleteSMS(gsm
, Backup
.SMS
[j
]);
106 fprintf(stderr
, "\r");
107 fprintf(stderr
, "%s ", _("Deleting:"));
108 fprintf(stderr
, _("%i percent"),
109 (j
+ 1) * 100 / smsnum
);
113 GSM_FreeSMSBackup(&Backup
);
118 void AddSMS(int argc UNUSED
, char *argv
[])
121 GSM_MultiSMSMessage SMS
;
122 GSM_SMS_Backup Backup
;
126 if (argc
== 5 && strcasecmp(argv
[4],"-yes") == 0) always_answer_yes
= TRUE
;
128 folder
= GetInt(argv
[2]);
130 error
= GSM_ReadSMSBackupFile(argv
[3], &Backup
);
135 while (Backup
.SMS
[smsnum
] != NULL
) {
136 Backup
.SMS
[smsnum
]->Folder
= folder
;
137 Backup
.SMS
[smsnum
]->SMSC
.Location
= 1;
139 SMS
.SMS
[0] = *Backup
.SMS
[smsnum
];
140 DisplayMultiSMSInfo(&SMS
,FALSE
,FALSE
,NULL
, gsm
);
141 if (answer_yes("%s", _("Restore message?"))) {
142 error
=GSM_AddSMS(gsm
, Backup
.SMS
[smsnum
]);
148 /* We don't need this anymore */
149 GSM_FreeSMSBackup(&Backup
);
154 void RestoreSMS(int argc
, char *argv
[])
157 GSM_MultiSMSMessage SMS
;
158 GSM_SMS_Backup Backup
;
159 GSM_SMSFolders folders
;
161 gboolean restore8bit
;
163 if (argc
== 4 && strcasecmp(argv
[3],"-yes") == 0) always_answer_yes
= TRUE
;
165 error
= GSM_ReadSMSBackupFile(argv
[2], &Backup
);
168 restore8bit
= answer_yes("%s", _("Do you want to restore binary SMS?"));
172 error
= GSM_GetSMSFolders(gsm
, &folders
);
175 while (Backup
.SMS
[smsnum
] != NULL
) {
176 if (restore8bit
|| Backup
.SMS
[smsnum
]->Coding
!= SMS_Coding_8bit
) {
178 memcpy(&SMS
.SMS
[0],Backup
.SMS
[smsnum
],sizeof(GSM_SMSMessage
));
179 DisplayMultiSMSInfo(&SMS
,FALSE
,FALSE
,NULL
, gsm
);
180 if (answer_yes(_("Restore %03i sms to folder \"%s\"%s?"),
182 DecodeUnicodeConsole(folders
.Folder
[Backup
.SMS
[smsnum
]->Folder
- 1].Name
),
183 folders
.Folder
[Backup
.SMS
[smsnum
]->Folder
- 1].Memory
== MEM_SM
? _(" (SIM)") : "")) {
184 smprintf(gsm
, _("saving %i SMS\n"),smsnum
);
185 error
= GSM_AddSMS(gsm
, Backup
.SMS
[smsnum
]);
192 /* We don't need this anymore */
193 GSM_FreeSMSBackup(&Backup
);
198 /* How should editor hadle tabs in this file? Add editor commands here.
199 * vim: noexpandtab sw=8 ts=8 sts=8: