/[mailutils]/mailutils/mh/mh_init.c
ViewVC logotype

Diff of /mailutils/mh/mh_init.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14 by gray, Thu Sep 19 15:00:30 2002 UTC revision 1.15 by gray, Sat Sep 21 19:12:55 2002 UTC
# Line 23  Line 23 
23  #include <sys/stat.h>  #include <sys/stat.h>
24  #include <stdarg.h>  #include <stdarg.h>
25    
 char *current_folder = NULL;  
 size_t current_message = 0;  
 mh_context_t *context;  
 mh_context_t *profile;  
 mh_context_t *sequences;  
   
26  char mh_list_format[] =  char mh_list_format[] =
27  "%4(msg)%<(cur)+%| %>%<{replied}-%?{encrypted}E%| %>"  "%4(msg)%<(cur)+%| %>%<{replied}-%?{encrypted}E%| %>"
28  "%02(mon{date})/%02(mday{date})"  "%02(mon{date})/%02(mday{date})"
# Line 61  mh_init () Line 55  mh_init ()
55  void  void
56  mh_init2 ()  mh_init2 ()
57  {  {
58    char *mh_sequences_name;    mh_current_folder ();
59    char *seq_name, *ctx_name;    mh_global_sequences_get ("cur", NULL);
   char *p;  
   
   mu_path_folder_dir = mh_get_dir ();  
   p = getenv ("CONTEXT");  
   if (!p)  
     p = "context";  
   ctx_name = mh_expand_name (p, 0);  
   context = mh_context_create (ctx_name, 1);  
   mh_context_read (context);  
     
   if (current_folder)  
     current_folder = mu_tilde_expansion (current_folder, "/", NULL);  
   else  
     current_folder = mh_context_get_value (context, "Current-Folder",  
                                            mh_profile_value ("Inbox",  
                                                              "inbox"));  
   
   mh_sequences_name = mh_profile_value ("mh-sequences", MH_SEQUENCES_FILE);  
   p = mh_expand_name (current_folder, 0);  
   asprintf (&seq_name, "%s/%s", p, mh_sequences_name);  
   free (p);  
   sequences = mh_context_create (seq_name, 1);  
   if (mh_context_read (sequences) == 0)  
     {  
       p = mh_context_get_value (sequences, "cur", "0");  
       current_message = strtoul (p, NULL, 10);  
     }  
 }  
   
 char *  
 mh_profile_value (char *name, char *defval)  
 {  
   return mh_context_get_value (profile, name, defval);  
 }  
   
 void  
 mh_read_profile ()  
 {  
   char *p;  
     
   p = getenv ("MH");  
   if (p)  
     p = mu_tilde_expansion (p, "/", NULL);  
   else  
     {  
       char *home = mu_get_homedir ();  
       if (!home)  
         abort (); /* shouldn't happen */  
       asprintf (&p, "%s/%s", home, MH_USER_PROFILE);  
       free (home);  
     }  
   profile = mh_context_create (p, 1);  
   mh_context_read (profile);  
 }  
     
 void  
 mh_save_context ()  
 {  
   char buf[64];  
   snprintf (buf, sizeof buf, "%d", current_message);  
   mh_context_set_value (sequences, "cur", buf);  
   mh_context_write (sequences);  
60  }  }
61    
62  int  int
# Line 207  mh_is_my_name (char *name) Line 139  mh_is_my_name (char *name)
139  }  }
140    
141  int  int
142  mh_check_folder (char *pathname)  mh_check_folder (char *pathname, int confirm)
143  {  {
144    char *p;    char *p;
145    struct stat st;    struct stat st;
# Line 221  mh_check_folder (char *pathname) Line 153  mh_check_folder (char *pathname)
153      {      {
154        if (errno == ENOENT)        if (errno == ENOENT)
155          {          {
156            if (mh_getyn ("Create folder \"%s\"", p))            if (!confirm || mh_getyn ("Create folder \"%s\"", p))
157              {              {
158                int perm = 0711;                int perm = 0711;
159                char *pb = mh_profile_value ("Folder-Protect", NULL);                char *pb = mh_global_profile_get ("Folder-Protect", NULL);
160                if (pb)                if (pb)
161                  perm = strtoul (pb, NULL, 8);                  perm = strtoul (pb, NULL, 8);
162                if (mkdir (p, perm))                if (mkdir (p, perm))
# Line 354  mh_open_folder (const char *folder, int Line 286  mh_open_folder (const char *folder, int
286    int flags = MU_STREAM_READ;    int flags = MU_STREAM_READ;
287        
288    name = mh_expand_name (folder, 1);    name = mh_expand_name (folder, 1);
289    if (create && mh_check_folder (name))    if (create && mh_check_folder (name, 1))
290      exit (0);      exit (0);
291            
292    if (mailbox_create_default (&mbox, name))    if (mailbox_create_default (&mbox, name))
# Line 381  mh_open_folder (const char *folder, int Line 313  mh_open_folder (const char *folder, int
313  char *  char *
314  mh_get_dir ()  mh_get_dir ()
315  {  {
316    char *mhdir = mh_profile_value ("Path", "Mail");    char *mhdir = mh_global_profile_get ("Path", "Mail");
317    if (mhdir[0] != '/')    if (mhdir[0] != '/')
318      {      {
319        char *p = mu_get_homedir ();        char *p = mu_get_homedir ();

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26