1 #include <string.h>
2 #include <stdarg.h>
3 #include <stdlib.h>
4 
5 #include "../helper/locales.h"
6 
7 #include "common.h"
8 #include "message.h"
9 #include "../helper/formats.h"
10 #include "calendar.h"
11 
12 #include "../helper/memory-display.h"
13 #include "../helper/printing.h"
14 #include "../libgammu/misc/string.h"
15 
16 
GetMMSFolders(int argc UNUSED,char * argv[]UNUSED)17 void GetMMSFolders(int argc UNUSED, char *argv[] UNUSED)
18 {
19 	GSM_Error error;
20 	GSM_MMSFolders folders;
21 	int i;
22 
23 	GSM_Init(TRUE);
24 
25 	error=GSM_GetMMSFolders(gsm,&folders);
26 	Print_Error(error);
27 
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");
32 	}
33 
34 	GSM_Terminate();
35 }
36 
DecodeMMSFile(GSM_File * file,int num)37 void DecodeMMSFile(GSM_File *file, int num)
38 {
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;
48 
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);
56 		}
57 		fclose(file2);
58 	}
59 
60 	for (i=0;i<GSM_MAX_MULTI_MMS;i++) info.Entries[i].File.Buffer = NULL;
61 	GSM_ClearMMSMultiPart(&info);
62 
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;
67 	}
68 	Print_Error(error);
69 
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;
75 		}
76 		printf("%s\n",DecodeUnicodeString(info.Source));
77 	}
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;
83 		}
84 		printf("%s\n",DecodeUnicodeString(info.Destination));
85 	}
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;
91 		}
92 		printf("%s\n",DecodeUnicodeString(info.CC));
93 	}
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));
98 	}
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"));
105 		}
106 	}
107 	printf(LISTFORMAT "%s\n", _("Content type"), DecodeUnicodeString(info.ContentType));
108 
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));
115 			}
116 			printf("\n");
117 		}
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);
123 		}
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);
129 		}
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);
137 			}
138 			fclose(file2);
139 		}
140 
141 	}
142 
143 	GSM_ClearMMSMultiPart(&info);
144 }
145 
GetEachMMS(int argc,char * argv[])146 void GetEachMMS(int argc, char *argv[])
147 {
148 	int FileFolder;
149 	GSM_File		File;
150 	gboolean			start = TRUE;
151 	GSM_MMSFolders 		folders;
152 	int			Handle,num = -1;
153 	size_t			Size;
154 	GSM_Error error;
155 
156 	if (argc>2 && strcasecmp(argv[2],"-save") == 0) num=0;
157 
158 	GSM_Init(TRUE);
159 
160 	error=GSM_GetMMSFolders(gsm,&folders);
161 	Print_Error(error);
162 
163 	File.Buffer = NULL;
164 
165 	while (1) {
166 		error = GSM_GetNextMMSFileInfo(gsm,File.ID_FullName,&FileFolder,start);
167 		if (error == ERR_EMPTY) break;
168 		Print_Error(error);
169 		start = FALSE;
170 
171 		printf(_("Folder %s\n"),DecodeUnicodeConsole(folders.Folder[FileFolder-1].Name));
172 		printf(LISTFORMAT "\"%s\"\n", _("  File filesystem ID"),DecodeUnicodeConsole(File.ID_FullName));
173 		if (File.Buffer != NULL) {
174 			free(File.Buffer);
175 			File.Buffer = NULL;
176 		}
177 		File.Used = 0;
178 		while (TRUE) {
179 			error = GSM_GetFilePart(gsm,&File,&Handle,&Size);
180 			if (error == ERR_EMPTY) break;
181 			Print_Error(error);
182 			fprintf(stderr, "\r");
183 			fprintf(stderr, "%s ", _("Reading:"));
184 			fprintf(stderr, _("%i percent"),
185 				(int)(File.Used * 100 / Size));
186 		}
187 		fprintf(stderr, "%c",13);
188 
189 		if (GSM_IsPhoneFeatureAvailable(GSM_GetModelInfo(gsm), F_SERIES40_30) && File.Used > 176) {
190 			memmove(File.Buffer, File.Buffer + 176, File.Used - 176);
191 			File.Used -= 176;
192 			File.Buffer = realloc(File.Buffer, File.Used);
193 		}
194 
195 		DecodeMMSFile(&File,num);
196 		if (num != -1) num++;
197 	}
198 
199 	if (File.Buffer != NULL) free(File.Buffer);
200 
201 	GSM_Terminate();
202 }
203 
ReadMMSFile(int argc,char * argv[])204 void ReadMMSFile(int argc, char *argv[])
205 {
206 	GSM_File		File;
207 	int			num = -1;
208 	GSM_Error error;
209 
210 	File.Buffer = NULL;
211 	error = GSM_ReadFile(argv[2], &File);
212 	Print_Error(error);
213 
214 	if (argc>3 && strcasecmp(argv[3],"-save") == 0) num=0;
215 
216 	DecodeMMSFile(&File,num);
217 
218 	free(File.Buffer);
219 }
220 
221 /* How should editor hadle tabs in this file? Add editor commands here.
222  * vim: noexpandtab sw=8 ts=8 sts=8:
223  */
224 
225