Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

work on sample, added pop sample

  • Loading branch information...
commit daf87a2a10a17b76a8236616dbe89efc7c6ed131 1 parent 643dcd2
@dinhviethoa authored
View
2  tests/imap-sample.c
@@ -66,7 +66,7 @@ static void fetch_msg(struct mailimap * imap, uint32_t uid)
{
struct mailimap_set * set;
struct mailimap_section * section;
- char filename[20];
+ char filename[512];
size_t msg_len;
char * msg_content;
FILE * f;
View
2  tests/mime-create.c
@@ -272,7 +272,7 @@ static char * generate_boundary(const char * boundary_prefix)
return strdup(id);
}
-struct mailmime * part_multiple_new(const char * type, const char * boundary_prefix)
+static struct mailmime * part_multiple_new(const char * type, const char * boundary_prefix)
{
struct mailmime_fields * mime_fields;
struct mailmime_content * content;
View
12 tests/mime-parse.c
@@ -17,12 +17,12 @@ static void display_mime_data(struct mailmime_data * data)
}
}
-void display_mime_parameter(struct mailmime_parameter * param)
+static void display_mime_parameter(struct mailmime_parameter * param)
{
printf("%s = %s\n", param->pa_name, param->pa_value);
}
-void display_mime_dsp_parm(struct mailmime_disposition_parm * param)
+static void display_mime_dsp_parm(struct mailmime_disposition_parm * param)
{
switch (param->pa_type) {
case MAILMIME_DISPOSITION_PARM_FILENAME:
@@ -31,7 +31,7 @@ void display_mime_dsp_parm(struct mailmime_disposition_parm * param)
}
}
-void display_mime_disposition(struct mailmime_disposition * disposition)
+static void display_mime_disposition(struct mailmime_disposition * disposition)
{
clistiter * cur;
@@ -216,7 +216,7 @@ static void display_fields(struct mailimf_fields * fields)
}
}
-void display_mime_discrete_type(struct mailmime_discrete_type * discrete_type)
+static void display_mime_discrete_type(struct mailmime_discrete_type * discrete_type)
{
switch (discrete_type->dt_type) {
case MAILMIME_DISCRETE_TYPE_TEXT:
@@ -240,7 +240,7 @@ void display_mime_discrete_type(struct mailmime_discrete_type * discrete_type)
}
}
-void display_mime_composite_type(struct mailmime_composite_type * ct)
+static void display_mime_composite_type(struct mailmime_composite_type * ct)
{
switch (ct->ct_type) {
case MAILMIME_COMPOSITE_TYPE_MESSAGE:
@@ -255,7 +255,7 @@ void display_mime_composite_type(struct mailmime_composite_type * ct)
}
}
-void display_mime_type(struct mailmime_type * type)
+static void display_mime_type(struct mailmime_type * type)
{
switch (type->tp_type) {
case MAILMIME_TYPE_DISCRETE_TYPE:
View
82 tests/pop-sample.c
@@ -0,0 +1,82 @@
+#include <libetpan/libetpan.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+
+static void check_error(int r, char * msg)
+{
+ if (r == MAILPOP3_NO_ERROR)
+ return;
+
+ fprintf(stderr, "%s\n", msg);
+ exit(EXIT_FAILURE);
+}
+
+int main(int argc, char ** argv)
+{
+ mailpop3 * pop3;
+ int r;
+ carray * list;
+ unsigned int i;
+
+ if (argc < 3) {
+ fprintf(stderr, "syntax: pop-sample [gmail-email-address] [gmail-password]\n");
+ exit(EXIT_FAILURE);
+ }
+
+ mkdir("download", 0700);
+
+ pop3 = mailpop3_new(0, NULL);
+ r = mailpop3_ssl_connect(pop3, "pop.gmail.com", 995);
+ check_error(r, "connect failed");
+
+ r = mailpop3_user(pop3, argv[1]);
+ check_error(r, "user failed");
+
+ r = mailpop3_pass(pop3, argv[2]);
+ check_error(r, "pass failed");
+
+ r = mailpop3_list(pop3, &list);
+ check_error(r, "list failed");
+
+ for(i = 0 ; i < carray_count(list) ; i ++) {
+ struct mailpop3_msg_info * info;
+ char * msg_content;
+ size_t msg_size;
+ FILE * f;
+ char filename[512];
+ struct stat stat_info;
+
+ info = carray_get(list, i);
+
+ if (info->msg_uidl == NULL) {
+ continue;
+ }
+
+ snprintf(filename, sizeof(filename), "download/%s.eml", info->msg_uidl);
+ r = stat(filename, &stat_info);
+ if (r == 0) {
+ printf("already fetched %u %s\n", info->msg_index, info->msg_uidl);
+ continue;
+ }
+
+ r = mailpop3_retr(pop3, info->msg_index, &msg_content, &msg_size);
+ check_error(r, "get failed");
+
+ f = fopen(filename, "w");
+ fwrite(msg_content, 1, msg_size, f);
+ fclose(f);
+ mailpop3_retr_free(msg_content);
+
+ if (info->msg_uidl != NULL) {
+ printf("fetched %u %s\n", info->msg_index, info->msg_uidl);
+ }
+ else {
+ printf("fetched %u\n", info->msg_index);
+ }
+ }
+
+ mailpop3_quit(pop3);
+ mailpop3_free(pop3);
+
+ exit(EXIT_SUCCESS);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.