barebone.c (1451B)
1 /* 2 * Copy me if you can. 3 * by 20h 4 */ 5 6 #include <unistd.h> 7 #include <stdio.h> 8 #include <stdlib.h> 9 10 #include "ind.h" 11 #include "arg.h" 12 #include "cfg.h" 13 #include "llist.h" 14 #include "folder.h" 15 #include "imap.h" 16 #include "flag.h" 17 18 char *argv0; 19 20 void 21 flagusage(void) 22 { 23 fprintf(stderr, "usage: %s [-h] [-c cfg] [[-s|-d] flag] [msgs]\n", 24 argv0); 25 exit(1); 26 } 27 28 int 29 flagmain(int argc, char *argv[]) 30 { 31 config_t *cfg; 32 imap_t *imap; 33 int status; 34 char *user, *pass, *netspec, *selected, *cfgn; 35 llist_t *folders, *ffolders, *statusl, *ids; 36 llistelem_t *folder, *elem; 37 38 enum { 39 BEQUIET = 0x01, 40 DOSET = 0x02, 41 DODELETE = 0x04, 42 43 NOARGS = 0x08 44 }; 45 46 status = 0; 47 cfgn = NULL; 48 49 ARGBEGIN { 50 case 'c': 51 cfgn = EARGF(flagusage()); 52 break; 53 case 'q': 54 status |= BEQUIET; 55 break; 56 case 's': 57 status |= PRINTSYNTAX; 58 break; 59 case 'd': 60 status |= DRYRUN; 61 break; 62 case 'e': 63 addseq = EARGF(flagusage()); 64 break; 65 default: 66 incusage(); 67 } ARGEND; 68 69 cfg = config_init(cfgn); 70 user = config_checkgetstr(cfg, "imapuser"); 71 pass = config_checkgetstr(cfg, "imappass"); 72 netspec = config_checkgetstr(cfg, "netspec"); 73 selected = config_checkgetstr(cfg, "selected"); 74 config_free(cfg); 75 imap = imap_new(netspec, user, pass); 76 free(user); 77 free(pass); 78 free(netspec); 79 80 if (imap_init(imap)) 81 imap_die(imap, "imap_init"); 82 if (imap_select(imap, selected)) 83 imap_die(imap, "imap_select"); 84 85 free(selected); 86 imap_close(imap); 87 imap_free(imap); 88 return 0; 89 } 90