gnu indented
Showing
2 changed files
with
128 additions
and
87 deletions
... | @@ -37,7 +37,7 @@ char from[256]; | ... | @@ -37,7 +37,7 @@ char from[256]; |
37 | char subject[256]; | 37 | char subject[256]; |
38 | 38 | ||
39 | int | 39 | int |
40 | main(int argc, char **argv) | 40 | main (int argc, char **argv) |
41 | { | 41 | { |
42 | mailbox_t mbox = NULL; | 42 | mailbox_t mbox = NULL; |
43 | int ret; | 43 | int ret; |
... | @@ -59,64 +59,73 @@ main(int argc, char **argv) | ... | @@ -59,64 +59,73 @@ main(int argc, char **argv) |
59 | list_append (bookie, imap_record); | 59 | list_append (bookie, imap_record); |
60 | } | 60 | } |
61 | 61 | ||
62 | if ( ( ret = mailbox_create_default (&mbox, mailbox_name) ) != 0) { | 62 | if ((ret = mailbox_create_default (&mbox, mailbox_name)) != 0) |
63 | fprintf (stderr, "could not create - %s\n", strerror(ret)); | 63 | { |
64 | fprintf (stderr, "could not create - %s\n", strerror (ret)); | ||
64 | exit (2); | 65 | exit (2); |
65 | } | 66 | } |
66 | 67 | ||
67 | /* Debuging Trace. */ | 68 | /* Debuging Trace. */ |
68 | if ( 0 ) { | 69 | if (0) |
70 | { | ||
69 | mu_debug_t debug; | 71 | mu_debug_t debug; |
70 | mailbox_get_debug (mbox, &debug); | 72 | mailbox_get_debug (mbox, &debug); |
71 | mu_debug_set_level (debug, MU_DEBUG_TRACE|MU_DEBUG_PROT); | 73 | mu_debug_set_level (debug, MU_DEBUG_TRACE | MU_DEBUG_PROT); |
72 | } | 74 | } |
73 | 75 | ||
74 | /* Open the mailbox for reading only. */ | 76 | /* Open the mailbox for reading only. */ |
75 | if ( ( ret = mailbox_open (mbox, MU_STREAM_RDWR) ) != 0) { | 77 | if ((ret = mailbox_open (mbox, MU_STREAM_RDWR)) != 0) |
76 | fprintf (stderr, "could not open - %s\n", strerror(ret)); | 78 | { |
79 | fprintf (stderr, "could not open - %s\n", strerror (ret)); | ||
77 | exit (2); | 80 | exit (2); |
78 | } | 81 | } |
79 | 82 | ||
80 | /* Iterator through the entire message set. */ | 83 | /* Iterator through the entire message set. */ |
81 | mailbox_messages_count (mbox, &count); | 84 | mailbox_messages_count (mbox, &count); |
82 | for(i = 1; i <= count; ++i) { | 85 | for (i = 1; i <= count; ++i) |
86 | { | ||
83 | message_t msg; | 87 | message_t msg; |
84 | header_t hdr; | 88 | header_t hdr; |
85 | size_t nparts; | 89 | size_t nparts; |
86 | size_t msize; | 90 | size_t msize; |
87 | 91 | ||
88 | if (( ret = mailbox_get_message (mbox, i, &msg) ) != 0) { | 92 | if ((ret = mailbox_get_message (mbox, i, &msg)) != 0) |
89 | fprintf (stderr, "mailbox_get_message - %s\n", strerror(ret)); | 93 | { |
90 | exit(2); | 94 | fprintf (stderr, "mailbox_get_message - %s\n", strerror (ret)); |
95 | exit (2); | ||
91 | } | 96 | } |
92 | if (( ret = message_size (msg, &msize) ) != 0) { | 97 | if ((ret = message_size (msg, &msize)) != 0) |
93 | fprintf (stderr, "message_size - %s\n", strerror(ret)); | 98 | { |
94 | exit(2); | 99 | fprintf (stderr, "message_size - %s\n", strerror (ret)); |
100 | exit (2); | ||
95 | } | 101 | } |
96 | if (( ret = message_get_header (msg, &hdr) ) != 0) { | 102 | if ((ret = message_get_header (msg, &hdr)) != 0) |
97 | fprintf (stderr, "message_get_header - %s\n", strerror(ret)); | 103 | { |
98 | exit(2); | 104 | fprintf (stderr, "message_get_header - %s\n", strerror (ret)); |
105 | exit (2); | ||
99 | } | 106 | } |
100 | header_get_value (hdr, MU_HEADER_FROM, from, sizeof (from), NULL); | 107 | header_get_value (hdr, MU_HEADER_FROM, from, sizeof (from), NULL); |
101 | header_get_value (hdr, MU_HEADER_SUBJECT, subject, sizeof (subject), NULL); | 108 | header_get_value (hdr, MU_HEADER_SUBJECT, subject, sizeof (subject), |
102 | printf("From: %s\tSubject: %s\n", from, subject); | 109 | NULL); |
103 | if ( ( ret = message_get_num_parts(msg, &nparts) ) != 0 ) { | 110 | printf ("From: %s\tSubject: %s\n", from, subject); |
104 | fprintf (stderr, "message_get_num_parts - %s\n", strerror(ret)); | 111 | if ((ret = message_get_num_parts (msg, &nparts)) != 0) |
105 | exit(2); | 112 | { |
106 | } | 113 | fprintf (stderr, "message_get_num_parts - %s\n", strerror (ret)); |
107 | printf("-- Number of parts in message - %d\n",nparts); | 114 | exit (2); |
108 | printf("-- Total message size - %d\n",msize); | 115 | } |
109 | message_display_parts(msg, "\t"); | 116 | printf ("-- Number of parts in message - %d\n", nparts); |
110 | } | 117 | printf ("-- Total message size - %d\n", msize); |
111 | mailbox_close(mbox); | 118 | message_display_parts (msg, "\t"); |
112 | mailbox_destroy(&mbox); | 119 | } |
120 | mailbox_close (mbox); | ||
121 | mailbox_destroy (&mbox); | ||
113 | return 0; | 122 | return 0; |
114 | } | 123 | } |
115 | 124 | ||
116 | char buf[2048]; | 125 | char buf[2048]; |
117 | 126 | ||
118 | void | 127 | void |
119 | message_display_parts(message_t msg, char *indent) | 128 | message_display_parts (message_t msg, char *indent) |
120 | { | 129 | { |
121 | int ret, j; | 130 | int ret, j; |
122 | size_t msize, nparts, nsubparts; | 131 | size_t msize, nparts, nsubparts; |
... | @@ -130,91 +139,123 @@ message_display_parts(message_t msg, char *indent) | ... | @@ -130,91 +139,123 @@ message_display_parts(message_t msg, char *indent) |
130 | size_t nbytes; | 139 | size_t nbytes; |
131 | 140 | ||
132 | /* How many part those the message has? */ | 141 | /* How many part those the message has? */ |
133 | if ( ( ret = message_get_num_parts(msg, &nparts) ) != 0 ) { | 142 | if ((ret = message_get_num_parts (msg, &nparts)) != 0) |
134 | fprintf (stderr, "message_get_num_parts - %s\n", strerror(ret)); | 143 | { |
135 | exit(2); | 144 | fprintf (stderr, "message_get_num_parts - %s\n", strerror (ret)); |
145 | exit (2); | ||
136 | } | 146 | } |
137 | 147 | ||
138 | /* Iterate through all the parts. | 148 | /* Iterate through all the parts. |
139 | Treat type "message/rfc822" differently, since it is a message of is own | 149 | Treat type "message/rfc822" differently, since it is a message of is own |
140 | that can have other subparts(recursive). */ | 150 | that can have other subparts(recursive). */ |
141 | for( j = 1; j <= nparts; j++) { | 151 | for (j = 1; j <= nparts; j++) |
142 | if (( ret = message_get_part(msg, j, &part ) ) != 0 ) { | 152 | { |
143 | fprintf (stderr, "mime_get_part - %s\n", strerror(ret)); | 153 | if ((ret = message_get_part (msg, j, &part)) != 0) |
144 | exit(2); | 154 | { |
145 | } | 155 | fprintf (stderr, "mime_get_part - %s\n", strerror (ret)); |
146 | if (( ret = message_size (part, &msize) ) != 0) { | 156 | exit (2); |
147 | fprintf (stderr, "message_size - %s\n", strerror(ret)); | 157 | } |
148 | exit(2); | 158 | if ((ret = message_size (part, &msize)) != 0) |
149 | } | 159 | { |
150 | if (( ret = message_get_header (part, &hdr) ) != 0) { | 160 | fprintf (stderr, "message_size - %s\n", strerror (ret)); |
151 | fprintf (stderr, "message_get_header - %s\n", strerror(ret)); | 161 | exit (2); |
152 | exit(2); | 162 | } |
153 | } | 163 | if ((ret = message_get_header (part, &hdr)) != 0) |
154 | header_get_value (hdr, MU_HEADER_CONTENT_TYPE, type, sizeof (type), NULL); | 164 | { |
155 | printf("%sType of part %d = %s\n", indent, j, type); | 165 | fprintf (stderr, "message_get_header - %s\n", strerror (ret)); |
156 | printf("%sMessage part size - %d\n",indent, msize); | 166 | exit (2); |
167 | } | ||
168 | header_get_value (hdr, MU_HEADER_CONTENT_TYPE, type, sizeof (type), | ||
169 | NULL); | ||
170 | printf ("%sType of part %d = %s\n", indent, j, type); | ||
171 | printf ("%sMessage part size - %d\n", indent, msize); | ||
157 | encoding[0] = '\0'; | 172 | encoding[0] = '\0'; |
158 | header_get_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING, encoding, sizeof (encoding), NULL); | 173 | header_get_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING, encoding, |
174 | sizeof (encoding), NULL); | ||
159 | ismulti = 0; | 175 | ismulti = 0; |
160 | if ( (type[0] && strncasecmp( type, "message/rfc822", strlen(type)) == 0 ) || | 176 | if ((type[0] |
161 | ( message_is_multipart (part, &ismulti) == 0 && ismulti ) ) { | 177 | && strncasecmp (type, "message/rfc822", strlen (type)) == 0) |
178 | || (message_is_multipart (part, &ismulti) == 0 && ismulti)) | ||
179 | { | ||
162 | char tmp[10]; | 180 | char tmp[10]; |
163 | 181 | ||
164 | if ( !ismulti ) { | 182 | if (!ismulti) |
165 | ret = message_unencapsulate(part, &part, NULL); | 183 | { |
184 | ret = message_unencapsulate (part, &part, NULL); | ||
166 | if (ret != 0) | 185 | if (ret != 0) |
167 | fprintf (stderr, "message_unencapsulate - %s\n", strerror(ret)); | 186 | fprintf (stderr, "message_unencapsulate - %s\n", |
187 | strerror (ret)); | ||
168 | break; | 188 | break; |
169 | } | 189 | } |
170 | if (( ret = message_get_header (part, &hdr) ) != 0) { | 190 | if ((ret = message_get_header (part, &hdr)) != 0) |
171 | fprintf (stderr, "message_get_header - %s\n", strerror(ret)); | 191 | { |
172 | exit(2); | 192 | fprintf (stderr, "message_get_header - %s\n", strerror (ret)); |
193 | exit (2); | ||
173 | } | 194 | } |
174 | header_get_value (hdr, MU_HEADER_FROM, from, sizeof (from), NULL); | 195 | header_get_value (hdr, MU_HEADER_FROM, from, sizeof (from), NULL); |
175 | header_get_value (hdr, MU_HEADER_SUBJECT, subject, sizeof (subject), NULL); | 196 | header_get_value (hdr, MU_HEADER_SUBJECT, subject, sizeof (subject), |
176 | printf("%sEncapsulated message : %s\t%s\n", indent, from, subject); | 197 | NULL); |
177 | printf("%s-------------------------------------------------------------------\n", indent); | 198 | printf ("%sEncapsulated message : %s\t%s\n", indent, from, subject); |
178 | if ( ( ret = message_get_num_parts(part, &nsubparts) ) != 0 ) { | 199 | printf |
179 | fprintf (stderr, "mime_get_num_parts - %s\n", strerror(ret)); | 200 | ("%s-------------------------------------------------------------------\n", |
180 | exit(2); | 201 | indent); |
181 | } | 202 | if ((ret = message_get_num_parts (part, &nsubparts)) != 0) |
182 | strcpy(tmp, indent); | 203 | { |
183 | strcat(tmp,"\t"); | 204 | fprintf (stderr, "mime_get_num_parts - %s\n", strerror (ret)); |
184 | message_display_parts(part, tmp); | 205 | exit (2); |
206 | } | ||
207 | strcpy (tmp, indent); | ||
208 | strcat (tmp, "\t"); | ||
209 | message_display_parts (part, tmp); | ||
185 | message_destroy (&part, NULL); | 210 | message_destroy (&part, NULL); |
186 | } | 211 | } |
187 | else if ( type[0] == '\0' || (strncasecmp( type, "text/plain", strlen("text/plain")) == 0) || (strncasecmp( type, "text/html", strlen("text/html")) == 0)) { | 212 | else if (type[0] == '\0' |
188 | printf("%sText Message\n",indent); | 213 | || (strncasecmp (type, "text/plain", strlen ("text/plain")) == |
189 | printf("%s-------------------------------------------------------------------\n", indent); | 214 | 0) |
190 | message_get_body(part, &body); | 215 | || (strncasecmp (type, "text/html", strlen ("text/html")) == |
191 | body_get_stream(body, &str); | 216 | 0)) |
192 | filter_create(&str, str, encoding, 0, 0); | 217 | { |
218 | printf ("%sText Message\n", indent); | ||
219 | printf | ||
220 | ("%s-------------------------------------------------------------------\n", | ||
221 | indent); | ||
222 | message_get_body (part, &body); | ||
223 | body_get_stream (body, &str); | ||
224 | filter_create (&str, str, encoding, 0, 0); | ||
193 | offset = 0; | 225 | offset = 0; |
194 | while( stream_readline( str, buf, sizeof(buf), offset, &nbytes ) == 0 && nbytes ) { | 226 | while (stream_readline (str, buf, sizeof (buf), offset, &nbytes) == |
195 | printf("%s%s", indent, buf); | 227 | 0 && nbytes) |
228 | { | ||
229 | printf ("%s%s", indent, buf); | ||
196 | offset += nbytes; | 230 | offset += nbytes; |
197 | } | 231 | } |
198 | stream_destroy(&str, NULL); | 232 | stream_destroy (&str, NULL); |
199 | } | 233 | } |
200 | else { | 234 | else |
235 | { | ||
201 | #if 1 | 236 | #if 1 |
202 | 237 | ||
203 | /* Save the attachements. */ | 238 | /* Save the attachements. */ |
204 | char *fname; | 239 | char *fname; |
205 | message_attachment_filename( part, &fname); | 240 | message_attachment_filename (part, &fname); |
206 | if ( fname == NULL ) { | 241 | if (fname == NULL) |
207 | char buffer[PATH_MAX+1]; | 242 | { |
208 | fname = tempnam(getcwd(buffer, PATH_MAX), "msg-" ); | 243 | char buffer[PATH_MAX + 1]; |
244 | fname = tempnam (getcwd (buffer, PATH_MAX), "msg-"); | ||
209 | } | 245 | } |
210 | printf("%sAttachment - saving [%s]\n",indent, fname); | 246 | printf ("%sAttachment - saving [%s]\n", indent, fname); |
211 | printf("%s-------------------------------------------------------------------\n", indent); | 247 | printf |
248 | ("%s-------------------------------------------------------------------\n", | ||
249 | indent); | ||
212 | /* FIXME: Somethings is not quite correct with this function. | 250 | /* FIXME: Somethings is not quite correct with this function. |
213 | Please fix. */ | 251 | Please fix. */ |
214 | message_save_attachment(part, fname, NULL); | 252 | message_save_attachment (part, fname, NULL); |
215 | free(fname); | 253 | free (fname); |
216 | #endif | 254 | #endif |
217 | } | 255 | } |
218 | printf("\n%s End -------------------------------------------------------------------\n", indent); | 256 | printf |
257 | ("\n%s End -------------------------------------------------------------------\n", | ||
258 | indent); | ||
219 | } | 259 | } |
220 | } | 260 | } |
261 | ... | ... |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment