Example #1
0
char *tcp_getline (TCPSTREAM *stream)
{
  unsigned long n,contd;
  char *ret = tcp_getline_work (stream,&n,&contd);
  if (ret && contd) {		/* got a line needing continuation? */
    STRINGLIST *stl = mail_newstringlist ();
    STRINGLIST *stc = stl;
    do {			/* collect additional lines */
      stc->text.data = (unsigned char *) ret;
      stc->text.size = n;
      stc = stc->next = mail_newstringlist ();
      ret = tcp_getline_work (stream,&n,&contd);
    } while (ret && contd);
    if (ret) {			/* stash final part of line on list */
      stc->text.data = (unsigned char *) ret;
      stc->text.size = n;
				/* determine how large a buffer we need */
      for (n = 0, stc = stl; stc; stc = stc->next) n += stc->text.size;
      ret = fs_get (n + 1);	/* copy parts into buffer */
      for (n = 0, stc = stl; stc; n += stc->text.size, stc = stc->next)
	memcpy (ret + n,stc->text.data,stc->text.size);
      ret[n] = '\0';
    }
    mail_free_stringlist (&stl);/* either way, done with list */
  }
  return ret;
}
Example #2
0
void mm_list(MAILSTREAM *stream, int delimiter, char *mailbox,
             long attributes) {
  STRINGLIST *cur=NIL;
  FOBJECTLIST *ocur=NIL;

  if (IMAPG(folderlist_style) == FLIST_OBJECT) {
    /* build up a the new array of objects */
    /* Author: CJH */
    if (IMAPG(folder_objects) == NIL) {
      IMAPG(folder_objects) = mail_newfolderobjectlist();
      IMAPG(folder_objects)->text.size =
        mm_strlen(IMAPG(folder_objects)->text.data=mm_cpystr(mailbox));
      IMAPG(folder_objects)->delimiter = delimiter;
      IMAPG(folder_objects)->attributes = attributes;
      IMAPG(folder_objects)->next = NIL;
      IMAPG(folder_objects_tail) = IMAPG(folder_objects);
    } else {
      ocur=IMAPG(folder_objects_tail);
      ocur->next=mail_newfolderobjectlist();
      ocur=ocur->next;
      ocur->text.size = mm_strlen(ocur->text.data = mm_cpystr(mailbox));
      ocur->delimiter = delimiter;
      ocur->attributes = attributes;
      ocur->next = NIL;
      IMAPG(folder_objects_tail) = ocur;
    }

  } else {
    /* build the old IMAPG(folders) variable to allow old
       imap_listmailbox() to work */
    if (!(attributes & LATT_NOSELECT)) {
      if (IMAPG(folders) == NIL) {
        IMAPG(folders)=mail_newstringlist();
        IMAPG(folders)->text.size =
          mm_strlen(IMAPG(folders)->text.data=mm_cpystr(mailbox));
        IMAPG(folders)->next=NIL;
        IMAPG(folders_tail) = IMAPG(folders);
      } else {
        cur=IMAPG(folders_tail);
        cur->next=mail_newstringlist ();
        cur=cur->next;
        cur->text.size = mm_strlen (cur->text.data = mm_cpystr (mailbox));
        cur->next = NIL;
        IMAPG(folders_tail) = cur;
      }
    }
  }
}
Example #3
0
void mm_lsub(MAILSTREAM *stream, int delimiter, char *mailbox,
             long attributes) {
  STRINGLIST *cur=NIL;
  FOBJECTLIST *ocur=NIL;

  if (IMAPG(folderlist_style) == FLIST_OBJECT) {
    /* build the array of objects */
    /* Author: CJH */
    if (IMAPG(sfolder_objects) == NIL) {
      IMAPG(sfolder_objects) = mail_newfolderobjectlist();
      IMAPG(sfolder_objects)->text.size =
        mm_strlen(IMAPG(sfolder_objects)->text.data=mm_cpystr(mailbox));
      IMAPG(sfolder_objects)->delimiter = delimiter;
      IMAPG(sfolder_objects)->attributes = attributes;
      IMAPG(sfolder_objects)->next = NIL;
      IMAPG(sfolder_objects_tail) = IMAPG(sfolder_objects);
    } else {
      ocur=IMAPG(sfolder_objects_tail);
      ocur->next=mail_newfolderobjectlist();
      ocur=ocur->next;
      ocur->text.size=mm_strlen(ocur->text.data = mm_cpystr(mailbox));
      ocur->delimiter = delimiter;
      ocur->attributes = attributes;
      ocur->next = NIL;
      IMAPG(sfolder_objects_tail) = ocur;
    }
  } else {
    /* build the old simple array for imap_listsubscribed() */
    if (IMAPG(sfolders) == NIL) {
      IMAPG(sfolders)=mail_newstringlist();
      IMAPG(sfolders)->text.size =
        mm_strlen(IMAPG(sfolders)->text.data=mm_cpystr(mailbox));
      IMAPG(sfolders)->next=NIL;
      IMAPG(sfolders_tail) = IMAPG(sfolders);
    } else {
      cur=IMAPG(sfolders_tail);
      cur->next=mail_newstringlist ();
      cur=cur->next;
      cur->text.size = mm_strlen (cur->text.data = mm_cpystr (mailbox));
      cur->next = NIL;
      IMAPG(sfolders_tail) = cur;
    }
  }
}
Example #4
0
/* Author: CJH */
void mm_notify(MAILSTREAM *stream, char *str, long errflg) {
  STRINGLIST *cur = NIL;
  if (strncmp(str, "[ALERT] ", 8) == 0) {
    if (IMAPG(alertstack) == NIL) {
      IMAPG(alertstack) = mail_newstringlist();
      IMAPG(alertstack)->text.size =
        mm_strlen((IMAPG(alertstack)->text.data = mm_cpystr(str)));
      IMAPG(alertstack)->next = NIL;
    } else {
      cur = IMAPG(alertstack);
      while (cur->next != NIL) {
        cur = cur->next;
      }
      cur->next = mail_newstringlist ();
      cur = cur->next;
      cur->text.size = mm_strlen(cur->text.data = mm_cpystr(str));
      cur->next = NIL;
    }
  }
}
Example #5
0
long
get_msgno_by_msg_id(MAILSTREAM *stream, char *message_id, MSGNO_S *msgmap)
{
    SEARCHPGM  *pgm = NULL;
    long        hint = mn_m2raw(msgmap, mn_get_cur(msgmap));
    long        newmsgno = -1L;
    int         iter = 0;
    MESSAGECACHE *mc;
    extern MAILSTREAM *mm_search_stream;
    extern long        mm_search_count;

    if(!(message_id && message_id[0]) || stream->nmsgs < 1L)
      return(newmsgno);

    mm_search_count = 0L;
    mm_search_stream = stream;
    while(mm_search_count == 0L && iter++ < 3
	  && (pgm = mail_newsearchpgm()) != NULL){
	pgm->message_id = mail_newstringlist();
	pgm->message_id->text.data = (unsigned char *) cpystr(message_id);
	pgm->message_id->text.size = strlen(message_id);

	if(iter > 1 || hint > stream->nmsgs)
	  iter++;

	if(iter == 1){
	    /* restrict to hint message on first try */
	    pgm->msgno = mail_newsearchset();
	    pgm->msgno->first = pgm->msgno->last = hint;
	}
	else if(iter == 2){
	    /* restrict to last 50 messages on 2nd try */
	    pgm->msgno = mail_newsearchset();
	    if(stream->nmsgs > 100L)
	      pgm->msgno->first = stream->nmsgs-50L;
	    else{
		pgm->msgno->first = 1L;
		iter++;
	    }

	    pgm->msgno->last = stream->nmsgs;
	}

	pine_mail_search_full(stream, NULL, pgm, SE_NOPREFETCH | SE_FREE);

	if(mm_search_count){
	    for(newmsgno=stream->nmsgs; newmsgno > 0L; newmsgno--)
	      if((mc = mail_elt(stream, newmsgno)) && mc->searched)
		break;
	}
    }

    return(mn_raw2m(msgmap, newmsgno));
}
Example #6
0
/*
 * Add all the entries from this file onto the Mailcap list.
 */
void
mc_process_file(char *file)
{
    char filebuf[MAXPATH+1], *file_data;

    dprint((5, "mailcap: process_file: %s\n", file ? file : "?"));

    (void)strncpy(filebuf, file, MAXPATH);
    filebuf[MAXPATH] = '\0';
    file = fnexpand(filebuf, sizeof(filebuf));
    dprint((7, "mailcap: processing file: %s\n", file ? file : "?"));
    switch(is_writable_dir(file)){
      case 0: case 1: /* is a directory */
	dprint((1, "mailcap: %s is a directory, should be a file\n",
	    file ? file : "?"));
	return;

      case 2: /* ok */
	break;

      case 3: /* doesn't exist */
	dprint((5, "mailcap: %s doesn't exist\n", file ? file : "?"));
	return;

      default:
	panic("Programmer botch in mc_process_file");
	/*NOTREACHED*/
    }

    if((file_data = read_file(file, READ_FROM_LOCALE)) != NULL){
	STRINGLIST *newsl, **sl;

	/* Create a new container */
	newsl		 = mail_newstringlist();
	newsl->text.data = (unsigned char *) file_data;

	/* figure out where in the list it should go */
	for(sl = &MailcapData.raw; *sl; sl = &((*sl)->next))
	  ;

	*sl = newsl;			/* Add it to the list */

	mc_parse_file(file_data);	/* the process mailcap data */
    }
    else
      dprint((5, "mailcap: %s can't be read\n", file ? file : "?"));
}
Example #7
0
/*
 * mc_init - Run down the path gathering all the mailcap entries.
 *           Returns with the Mailcap list built.
 */
void
mc_init(void)
{
    char *s,
	 *pathcopy,
	 *path,
	  image_viewer[MAILTMPLEN];
  
    if(MailcapData.raw)		/* already have the file? */
      return;
    else
      MailcapData.tail = &MailcapData.head;

    dprint((5, "- mc_init -\n"));

    pathcopy = mc_conf_path(ps_global->VAR_MAILCAP_PATH, getenv("MAILCAPS"),
			    MC_USER_FILE, MC_PATH_SEPARATOR, MC_STDPATH);

    path = pathcopy;			/* overloaded "path" */

    /*
     * Insert an entry for the image-viewer variable from .pinerc, if present.
     */
    if(ps_global->VAR_IMAGE_VIEWER && *ps_global->VAR_IMAGE_VIEWER){
	MailcapEntry *mc = mc_new_entry();

	snprintf(image_viewer, sizeof(image_viewer), "%s %%s", ps_global->VAR_IMAGE_VIEWER);

	MailcapData.raw		   = mail_newstringlist();
	MailcapData.raw->text.data = (unsigned char *) cpystr(image_viewer);
	mc->command		   = (char *) MailcapData.raw->text.data;
	mc->contenttype		   = "image/*";
	mc->label		   = "Alpine Image Viewer";
	dprint((5, "mailcap: using image-viewer=%s\n", 
		   ps_global->VAR_IMAGE_VIEWER
		     ? ps_global->VAR_IMAGE_VIEWER : "?"));
    }

    dprint((7, "mailcap: path: %s\n", path ? path : "?"));
    while(path){
	s = strindex(path, MC_PATH_SEPARATOR);
	if(s)
	  *s++ = '\0';
	mc_process_file(path);
	path = s;
    }
  
    if(pathcopy)
      fs_give((void **)&pathcopy);

#ifdef DEBUG
    if(debug >= 11){
	MailcapEntry *mc;
	int i = 0;

	dprint((11, "Collected mailcap entries\n"));
	for(mc = MailcapData.head; mc; mc = mc->next){

	    dprint((11, "%d: ", i++));
	    if(mc->label)
	      dprint((11, "%s\n", mc->label ? mc->label : "?"));
	    if(mc->contenttype)
	      dprint((11, "   %s",
		     mc->contenttype ? mc->contenttype : "?"));
	    if(mc->command)
	      dprint((11, "   command: %s\n",
		     mc->command ? mc->command : "?"));
	    if(mc->testcommand)
	      dprint((11, "   testcommand: %s",
		     mc->testcommand ? mc->testcommand : "?"));
	    if(mc->printcommand)
	      dprint((11, "   printcommand: %s",
		     mc->printcommand ? mc->printcommand : "?"));
	    dprint((11, "   needsterminal %d\n", mc->needsterminal));
	}
    }
#endif /* DEBUG */
}