Translation update done using Pootle.
[gammu.git] / gammu / mms.c
blob2fd97dcfa53c810813edbe7bfa64255c477b7c18
1 #include <string.h>
2 #include <stdarg.h>
3 #include <stdlib.h>
5 #include "../helper/locales.h"
7 #include "common.h"
8 #include "message.h"
9 #include "../helper/formats.h"
10 #include "calendar.h"
12 #include "../helper/memory-display.h"
13 #include "../helper/printing.h"
14 #include "../helper/string.h"
17 void GetMMSFolders(int argc UNUSED, char *argv[] UNUSED)
19 GSM_Error error;
20 GSM_MMSFolders folders;
21 int i;
23 GSM_Init(TRUE);
25 error=GSM_GetMMSFolders(gsm,&folders);
26 Print_Error(error);
28 for (i=0;i<folders.Number;i++) {
29 printf("%i. \"%s\"",i+1,DecodeUnicodeConsole(folders.Folder[i].Name));
30 if (folders.Folder[i].InboxFolder) printf("%s", _(", Inbox folder"));
31 printf("\n");
34 GSM_Terminate();
37 void DecodeMMSFile(GSM_File *file, int num)
39 int i;
40 size_t Pos;
41 char buff[200];
42 GSM_EncodedMultiPartMMSInfo info;
43 GSM_Error error;
44 FILE *file2;
45 GSM_MemoryEntry pbk;
46 GSM_CalendarEntry Calendar;
47 GSM_ToDoEntry ToDo;
49 if (num != -1 && answer_yes("%s", _("Do you want to save this MMS file?"))) {
50 sprintf(buff,"%i_0",num);
51 file2 = fopen(buff,"wb");
52 if (fwrite(file->Buffer, 1, file->Used, file2) != file->Used) {
53 printf_err(_("Error while saving to file %s!\n"), buff);
54 } else {
55 printf(_("Saved to file %s\n"),buff);
57 fclose(file2);
60 for (i=0;i<GSM_MAX_MULTI_MMS;i++) info.Entries[i].File.Buffer = NULL;
61 GSM_ClearMMSMultiPart(&info);
63 error = GSM_DecodeMMSFileToMultiPart(GSM_GetDebug(gsm), file, &info);
64 if (error == ERR_FILENOTSUPPORTED) {
65 printf_warn("%s\n", _("Some MMS file features unknown for Gammu decoder"));
66 return;
68 Print_Error(error);
70 if (UnicodeLength(info.Source) != 0) {
71 printf(LISTFORMAT, _("Sender"));
72 switch (info.SourceType) {
73 case MMSADDRESS_PHONE: printf("%s", _("phone ")); break;
74 default: break;
76 printf("%s\n",DecodeUnicodeString(info.Source));
78 if (UnicodeLength(info.Destination) != 0) {
79 printf(LISTFORMAT, _("Recipient"));
80 switch (info.DestinationType) {
81 case MMSADDRESS_PHONE: printf("%s", _("phone ")); break;
82 default: break;
84 printf("%s\n",DecodeUnicodeString(info.Destination));
86 if (UnicodeLength(info.CC) != 0) {
87 printf(LISTFORMAT, _("CC"));
88 switch (info.CCType) {
89 case MMSADDRESS_PHONE: printf("%s", _("phone ")); break;
90 default: break;
92 printf("%s\n",DecodeUnicodeString(info.CC));
94 printf(LISTFORMAT "%s\n", _("Message type"), info.MSGType);
95 if (info.DateTimeAvailable) printf(LISTFORMAT "%s\n", _("Date"), OSDateTime(info.DateTime,0));
96 if (UnicodeLength(info.Subject) != 0) {
97 printf(LISTFORMAT "%s\n", _("Subject"),DecodeUnicodeString(info.Subject));
99 if (info.MMSReportAvailable) {
100 printf(LISTFORMAT, _("Delivery report"));
101 if (info.MMSReport) {
102 printf("%s\n", _("enabled"));
103 } else {
104 printf("%s\n", _("disabled"));
107 printf(LISTFORMAT "%s\n", _("Content type"), DecodeUnicodeString(info.ContentType));
109 for (i=0;i<info.EntriesNum;i++) {
110 printf(LISTFORMAT "%s\n", _("Content type"), DecodeUnicodeString(info.Entries[i].ContentType));
111 if (UnicodeLength(info.Entries[i].File.Name) != 0) {
112 printf(LISTFORMAT "%s", _("Name"),DecodeUnicodeString(info.Entries[i].File.Name));
113 if (UnicodeLength(info.Entries[i].SMIL) != 0) {
114 printf(_(" (%s in SMIL)"),DecodeUnicodeString(info.Entries[i].SMIL));
116 printf("\n");
118 if (!strcmp(DecodeUnicodeString(info.Entries[i].ContentType),"text/x-vCard")) {
119 Pos = 0;
120 printf("\n");
121 error = GSM_DecodeVCARD(GSM_GetDebug(gsm), info.Entries[i].File.Buffer, &Pos, &pbk, Nokia_VCard21);
122 if (error == ERR_NONE) PrintMemoryEntry(&pbk, gsm);
124 if (!strcmp(DecodeUnicodeString(info.Entries[i].ContentType),"text/x-vCalendar")) {
125 Pos = 0;
126 printf("\n");
127 error = GSM_DecodeVCALENDAR_VTODO(GSM_GetDebug(gsm), info.Entries[i].File.Buffer, &Pos, &Calendar, &ToDo, Nokia_VCalendar, Nokia_VToDo);
128 if (error == ERR_NONE) PrintCalendar(&Calendar);
130 if (num != -1 && answer_yes("%s", _("Do you want to save this attachment?"))) {
131 sprintf(buff,"%i_%i_%s",num,i+1,DecodeUnicodeString(info.Entries[i].File.Name));
132 file2 = fopen(buff,"wb");
133 if (fwrite(info.Entries[i].File.Buffer, 1, info.Entries[i].File.Used, file2) != info.Entries[i].File.Used) {
134 printf_err(_("Error while saving to file %s!\n"), buff);
135 } else {
136 printf(_("Saved to file %s\n"),buff);
138 fclose(file2);
143 GSM_ClearMMSMultiPart(&info);
146 void GetEachMMS(int argc, char *argv[])
148 int FileFolder;
149 GSM_File File;
150 gboolean start = TRUE;
151 GSM_MMSFolders folders;
152 int Handle,Size,num = -1;
153 GSM_Error error;
155 if (argc>2 && strcasecmp(argv[2],"-save") == 0) num=0;
157 GSM_Init(TRUE);
159 error=GSM_GetMMSFolders(gsm,&folders);
160 Print_Error(error);
162 File.Buffer = NULL;
164 while (1) {
165 error = GSM_GetNextMMSFileInfo(gsm,File.ID_FullName,&FileFolder,start);
166 if (error == ERR_EMPTY) break;
167 Print_Error(error);
168 start = FALSE;
170 printf(_("Folder %s\n"),DecodeUnicodeConsole(folders.Folder[FileFolder-1].Name));
171 printf(LISTFORMAT "\"%s\"\n", _(" File filesystem ID"),DecodeUnicodeConsole(File.ID_FullName));
172 if (File.Buffer != NULL) {
173 free(File.Buffer);
174 File.Buffer = NULL;
176 File.Used = 0;
177 while (TRUE) {
178 error = GSM_GetFilePart(gsm,&File,&Handle,&Size);
179 if (error == ERR_EMPTY) break;
180 Print_Error(error);
181 fprintf(stderr, "\r");
182 fprintf(stderr, "%s ", _("Reading:"));
183 fprintf(stderr, _("%i percent"),
184 (int)(File.Used * 100 / Size));
186 fprintf(stderr, "%c",13);
188 if (GSM_IsPhoneFeatureAvailable(GSM_GetModelInfo(gsm), F_SERIES40_30)) {
189 memmove(File.Buffer,File.Buffer+176,File.Used-176);
190 File.Used-=176;
191 File.Buffer = realloc(File.Buffer,File.Used);
194 DecodeMMSFile(&File,num);
195 if (num != -1) num++;
198 if (File.Buffer != NULL) free(File.Buffer);
200 GSM_Terminate();
203 void ReadMMSFile(int argc, char *argv[])
205 GSM_File File;
206 int num = -1;
207 GSM_Error error;
209 File.Buffer = NULL;
210 error = GSM_ReadFile(argv[2], &File);
211 Print_Error(error);
213 if (argc>3 && strcasecmp(argv[3],"-save") == 0) num=0;
215 DecodeMMSFile(&File,num);
217 free(File.Buffer);
220 /* How should editor hadle tabs in this file? Add editor commands here.
221 * vim: noexpandtab sw=8 ts=8 sts=8: