Beispiel #1
0
/*
 * Argument is a color name which could be an RGB string, a name like "blue",
 * or a name like "color011".
 *
 * Returns a pointer to the canonical name of the color.
 */
char *
color_to_canonical_name(char *s)
{
    struct color_table *ct;
    struct color_name_list *nl;
    int done;

    if(!s || !color_tbl)
      return(NULL);
    
    if(*s == ' ' || isdigit(*s)){
	/* check for rgb string instead of name */
	for(ct = color_tbl; ct->rgb; ct++)
	  if(!strncmp(ct->rgb, s, RGBLEN))
	    break;
    }
    else{
	for(done=0, ct = color_tbl; !done && ct->names; ct++){
	  for(nl = ct->names; !done && nl; nl = nl->next)
	    if(nl->name && !struncmp(nl->name, s, nl->namelen))
	      done++;
	  
	  if(done)
	    break;
	}
    }
    
    /* rgb is the canonical name */
    if(ct->names)
      return(ct->rgb);
    else if(!struncmp(s, MATCH_NORM_COLOR, RGBLEN) || !struncmp(s, MATCH_NONE_COLOR, RGBLEN))
      return(s);
    
    return("");
}
Beispiel #2
0
int
df_valid_test(struct mail_bodystruct *body, char *test)
{
    int passed = 0;

    if(!(passed = !test)){			/* NO test always wins */
	if(!*test){
	    passed++;				/* NULL test also wins! */
	}
	else if(body && !struncmp(test, "_CHARSET(", 9)){
	    char *p = strrindex(test, ')');

	    if(p){
		*p = '\0';			/* tie off user charset */
		if((p = parameter_val(body->parameter,"charset")) != NULL){
		    passed = !strucmp(test + 9, p);
		    fs_give((void **) &p);
		}
		else
		  passed = !strucmp(test + 9, "us-ascii");
	    }
	    else
	      dprint((1,
			 "filter trigger: malformed test: %s\n",
			 test ? test : "?"));
	}
    }

    return(passed);
}
Beispiel #3
0
int
pico_set_bg_color(char *s)
{
    int val;

    if(!s || !color_tbl)
      return(FALSE);

    if(!strcmp(s, END_PSEUDO_REVERSE)){
	EndInverse();
	return(TRUE);
    }

    if(!struncmp(s, MATCH_NORM_COLOR, RGBLEN))
      s = _nbcolor;
    else if(!struncmp(s, MATCH_NONE_COLOR, RGBLEN))
      return(TRUE);

    if((val = color_to_val(s)) >= 0){
	size_t len;
	int changed;

	changed = !_last_bg_color || strcmp(_last_bg_color,colorx(val));

	/* already set correctly */
	if(!_force_bg_color_change && !changed)
	  return(TRUE);

	_force_bg_color_change = 0;

	if(changed){
	    if(_last_bg_color)
	      fs_give((void **) &_last_bg_color);
	    
	    len = strlen(colorx(val));
	    if((_last_bg_color = (char *) fs_get((len+1) * sizeof(char))) != NULL){
	      strncpy(_last_bg_color, colorx(val), len+1);
	      _last_bg_color[len] = '\0';
	    }
	}

	tbgcolor(val);
	return(TRUE);
    }
    else
      return(FALSE);
}
Beispiel #4
0
/*
 * Check whether the pattern "pat" matches this type/subtype.
 * Returns 1 if it does, 0 if not.
 */
int
mc_ctype_match(int type, char *subtype, char *pat)
{
    char *type_name = body_type_names(type);
    int   len = strlen(type_name);

    dprint((5, "mc_ctype_match: %s == %s / %s ?\n",
	       pat ? pat : "?",
	       type_name ? type_name : "?",
	       subtype ? subtype : "?"));

    return(!struncmp(type_name, pat, len)
	   && ((pat[len] == '/'
		&& (!pat[len+1] || pat[len+1] == '*'
		    || !strucmp(subtype, &pat[len+1])))
	       || !pat[len]));
}
Beispiel #5
0
/*
 * Argument is the name of a color or an RGB value that we recognize.
 * The table should be set up so that the val returned is the same whether
 * or not we choose the canonical name.
 *
 * Returns the integer value for the color.
 */
int
color_to_val(char *s)
{
    struct color_table *ct;
    struct color_name_list *nl;
    int done;

    if(!s || !color_tbl)
      return(-1);
    
    if(*s == ' ' || isdigit(*s)){
	/* check for rgb string instead of name */
	for(ct = color_tbl; ct->rgb; ct++)
	  if(!strncmp(ct->rgb, s, RGBLEN))
	    break;

	/*
	 * Didn't match any. Find "closest" to match.
	 */
	if(!ct->rgb){
	    int r = -1, g = -1, b = -1;
	    char *p, *comma, scopy[RGBLEN+1];

	    strncpy(scopy, s, sizeof(scopy));
	    scopy[sizeof(scopy)-1] = '\0';

	    p = scopy;
	    comma = strchr(p, ',');
	    if(comma){
	      *comma = '\0';
	      r = atoi(p);
	      p = comma+1;
	      if(r >= 0 && r <= 255 && *p){
		comma = strchr(p, ',');
		if(comma){
		  *comma = '\0';
		  g = atoi(p);
		  p = comma+1;
		  if(g >= 0 && g <= 255 && *p){
		    b = atoi(p);
		  }
		}
	      }
	    }

	    if(r >= 0 && r <= 255 && g >= 0 && g <= 255 && b >= 0 && b <= 255){
		struct color_table *closest = NULL;
		int closest_value = 1000000;
		int cv;

		for(ct = color_tbl; ct->rgb; ct++){

		    if(ct->red >= 0 && ct->red <= 255
		       && ct->green >= 0 && ct->green <= 255
		       && ct->blue >= 0 && ct->blue <= 255){
			cv = (ct->red - r) * (ct->red - r) +
			     (ct->green - g) * (ct->green - g) +
			     (ct->blue - b) * (ct->blue - b);
			if(cv < closest_value){
			    closest_value = cv;
			    closest = ct;
			}
		    }
		}

		if(closest)
		  ct = closest;
	    }
	}
    }
    else{
	for(done=0, ct = color_tbl; !done && ct->names; ct++){
	  for(nl = ct->names; !done && nl; nl = nl->next)
	    if(nl->name && !struncmp(nl->name, s, nl->namelen))
	      done++;
	  
	  if(done)
	    break;
	}
    }
    
    if(ct->names)
      return(ct->val);
    else
      return(-1);
}
Beispiel #6
0
/*
 * Return a pointer to an rgb string for the input color. The output is 11
 * characters long and looks like rrr,ggg,bbb.
 *
 * Args    colorName -- The color to convert to ascii rgb.
 *
 * Returns  Pointer to a static buffer containing the rgb string. Can use up
 * to three returned values at once before the first is overwritten.
 */
char *
color_to_asciirgb(char *colorName)
{
    static char c_to_a_buf[3][RGBLEN+1];
    static int whichbuf = 0;
    struct color_table *ct;
    struct color_name_list *nl;
    int done;

    whichbuf = (whichbuf + 1) % 3;

    c_to_a_buf[whichbuf][0] = '\0';

    for(done=0, ct = color_tbl; !done && ct->names; ct++){
      for(nl = ct->names; !done && nl; nl = nl->next)
	if(nl->name && !struncmp(nl->name, colorName, nl->namelen))
	  done++;
      
      if(done)
	break;
    }
    
    if(ct && ct->names){
	strncpy(c_to_a_buf[whichbuf], ct->rgb, sizeof(c_to_a_buf[0]));
	c_to_a_buf[whichbuf][sizeof(c_to_a_buf[0])-1] = '\0';
    }
    else if(*colorName == ' ' || isdigit(*colorName)){
	/* check for rgb string instead of name */
	for(ct = color_tbl; ct->rgb; ct++)
	  if(!strncmp(ct->rgb, colorName, RGBLEN))
	    break;

	/* if no match it's still ok if rgb */
	if(!ct->rgb){
	    int r = -1, g = -1, b = -1;
	    char *p, *comma, scopy[RGBLEN+1];

	    strncpy(scopy, colorName, sizeof(scopy));
	    scopy[sizeof(scopy)-1] = '\0';

	    p = scopy;
	    comma = strchr(p, ',');
	    if(comma){
	      *comma = '\0';
	      r = atoi(p);
	      p = comma+1;
	      if(r >= 0 && r <= 255 && *p){
		comma = strchr(p, ',');
		if(comma){
		  *comma = '\0';
		  g = atoi(p);
		  p = comma+1;
		  if(g >= 0 && g <= 255 && *p){
		    b = atoi(p);
		  }
		}
	      }
	    }

	    if(r >= 0 && r <= 255 && g >= 0 && g <= 255 && b >= 0 && b <= 255){
		/* it was already RGB */
		snprintf(c_to_a_buf[whichbuf], sizeof(c_to_a_buf[0]), "%3.3d,%3.3d,%3.3d", r, g, b);
	    }
	}
	else{
	    strncpy(c_to_a_buf[whichbuf], ct->rgb, sizeof(c_to_a_buf[0]));
	    c_to_a_buf[whichbuf][sizeof(c_to_a_buf[0])-1] = '\0';
	}
    }

    if(!c_to_a_buf[whichbuf][0]){
	int l;

	/*
	 * If we didn't find the color it could be that it is the
	 * normal color (MATCH_NORM_COLOR) or the none color
	 * (MATCH_NONE_COLOR). If that is the case, this strncpy thing
	 * will work out correctly because those two strings are
	 * RGBLEN long. Otherwise we're in a bit of trouble. This
	 * most likely means that the user is using the same pinerc on
	 * two terminals, one with more colors than the other. We didn't
	 * find a match because this color isn't present on this terminal.
	 * Since the return value of this function is assumed to be
	 * RGBLEN long, we'd better make it that long.
	 * It still won't work correctly because colors will be screwed up,
	 * but at least the embedded colors in filter.c will get properly
	 * sucked up when they're encountered.
	 */
	strncpy(c_to_a_buf[whichbuf], "xxxxxxxxxxx", RGBLEN);  /* RGBLEN is 11 */
	l = strlen(colorName);
	strncpy(c_to_a_buf[whichbuf], colorName, (l < RGBLEN) ? l : RGBLEN);
	c_to_a_buf[whichbuf][RGBLEN] = '\0';
    }
    
    return(c_to_a_buf[whichbuf]);
}
Beispiel #7
0
int
pico_is_good_color(char *s)
{
    struct color_table *ct;
    struct color_name_list *nl;
    int done;

    if(!s || !color_tbl)
      return(FALSE);

    if(!strcmp(s, END_PSEUDO_REVERSE))
      return(TRUE);
    else if(!struncmp(s, MATCH_NORM_COLOR, RGBLEN) || !struncmp(s, MATCH_NONE_COLOR, RGBLEN))
      return(TRUE);
    else if(*s == ' ' || isdigit(*s)){
	/* check for rgb string instead of name */
	for(ct = color_tbl; ct->rgb; ct++)
	  if(!strncmp(ct->rgb, s, RGBLEN))
	    break;

	/* if no match it's still ok if rgb */
	if(!ct->rgb){
	    int r = -1, g = -1, b = -1;
	    char *p, *comma, scopy[RGBLEN+1];

	    strncpy(scopy, s, sizeof(scopy));
	    scopy[sizeof(scopy)-1] = '\0';

	    p = scopy;
	    comma = strchr(p, ',');
	    if(comma){
	      *comma = '\0';
	      r = atoi(p);
	      p = comma+1;
	      if(r >= 0 && r <= 255 && *p){
		comma = strchr(p, ',');
		if(comma){
		  *comma = '\0';
		  g = atoi(p);
		  p = comma+1;
		  if(g >= 0 && g <= 255 && *p){
		    b = atoi(p);
		  }
		}
	      }
	    }

	    if(r >= 0 && r <= 255 && g >= 0 && g <= 255 && b >= 0 && b <= 255)
	      ct = color_tbl;	/* to force TRUE */
	}
    }
    else{
	for(done=0, ct = color_tbl; !done && ct->names; ct++){
	  for(nl = ct->names; !done && nl; nl = nl->next)
	    if(nl->name && !struncmp(nl->name, s, nl->namelen))
	      done++;
	  
	  if(done)
	    break;
	}
    }
    
    return(ct->names ? TRUE : FALSE);
}
Beispiel #8
0
char *
rfc2231_get_param(PARAMETER *parms, char *name,
		  char **charset, char **lang)
{
    char *buf, *p;
    int	  decode = 0, name_len, i;
    unsigned n;

    name_len = strlen(name);
    for(; parms ; parms = parms->next)
      if(!struncmp(name, parms->attribute, name_len)){
	if(parms->attribute[name_len] == '*'){
	    for(p = &parms->attribute[name_len + 1], n = 0; *(p+n); n++)
	      ;

	    decode = *(p + n - 1) == '*';

	    if(isdigit((unsigned char) *p)){
		char *pieces[RFC2231_MAX];
		int   count = 0, len;

		memset(pieces, 0, RFC2231_MAX * sizeof(char *));

		while(parms){
		    n = 0;
		    do
		      n = (n * 10) + (*p - '0');
		    while(isdigit(*++p) && n < RFC2231_MAX);

		    if(n < RFC2231_MAX){
			pieces[n] = parms->value;
			if(n > count)
			  count = n;
		    }
		    else{
			q_status_message1(SM_ORDER | SM_DING, 0, 3,
		   "Invalid attachment parameter segment number: %.25s",
					  name);
			return(NULL);		/* Too many segments! */
		    }

		    while((parms = parms->next) != NULL)
		      if(!struncmp(name, parms->attribute, name_len)){
			  if(*(p = &parms->attribute[name_len]) == '*'
			      && isdigit((unsigned char) *++p))
			    break;
			  else
			    return(NULL);	/* missing segment no.! */
		      }
		}

		for(i = len = 0; i <= count; i++)
		  if(pieces[i])
		    len += strlen(pieces[i]);
		  else{
		      q_status_message1(SM_ORDER | SM_DING, 0, 3,
		        "Missing attachment parameter sequence: %.25s",
					name);

		    return(NULL);		/* hole! */
		  }

		buf = (char *) fs_get((len + 1) * sizeof(char));

		for(i = len = 0; i <= count; i++){
		    if((n = *(p = pieces[i]) == '\"') != 0) /* quoted? */
		      p++;

		    while(*p && !(n && *p == '\"' && !*(p+1)))
		      buf[len++] = *p++;
		}

		buf[len] = '\0';
	    }
	    else
	      buf = cpystr(parms->value);

	    /* Do any RFC 2231 decoding? */
	    if(decode){
		char *converted = NULL, cs[1000];

		cs[0] = '\0';
		n = 0;

		if((p = strchr(buf, '\'')) != NULL){
		    n = (p - buf) + 1;
		    *p = '\0';
		    strncpy(cs, buf, sizeof(cs));
		    cs[sizeof(cs)-1] = '\0';
		    *p = '\'';
		    if(charset)
		      *charset = cpystr(cs);

		    if((p = strchr(&buf[n], '\'')) != NULL){
			n = (p - buf) + 1;
			if(lang){
			    *p = '\0';
			    *lang = cpystr(p);
			    *p = '\'';
			}
		    }
		}

		if(n){
		    /* Suck out the charset & lang while decoding hex */
		    p = &buf[n];
		    for(i = 0; (buf[i] = *p) != '\0'; i++)
		      if(*p++ == '%' && isxpair(p)){
			  buf[i] = X2C(p);
			  p += 2;
		      }
		}
		else
		  fs_give((void **) &buf);	/* problems!?! */

		/*
		 * Callers will expect the returned value to be UTF-8
		 * text, so we may need to translate here.
		 */
		if(buf)
		  converted = convert_to_utf8(buf, cs, 0);

		if(converted && converted != buf){
		    fs_give((void **) &buf);
		    buf = converted;
		}
	    }
	    
	    return(buf);
	}
	else
	  return(cpystr(parms->value ? parms->value : ""));
      }

    return(NULL);
}
Beispiel #9
0
/*
 * rfc1738_scan -- Scan the given line for possible URLs as defined
 *		   in RFC1738
 */
char *
rfc1738_scan(char *line, int *len)
{
    char *colon, *start, *end;
    int   n;

    /* process each : in the line */
    for(; (colon = strindex(line, ':')) != NULL; line = end){
	end = colon + 1;
	if(colon == line)		/* zero length scheme? */
	  continue;

	/*
	 * Valid URL (ala RFC1738 BNF)?  First, first look to the
	 * left to make sure there are valid "scheme" chars...
	 */
	start = colon - 1;
	while(1)
	  if(!(isdigit((unsigned char) *start)
	       || isalpha((unsigned char) *start)
	       || strchr("+-.", *start))){
	      start++;			/* advance over bogus char */
	      break;
	  }
	  else if(start > line)
	    start--;
	  else
	    break;

	/*
	 * Make sure everyhing up to the colon is a known scheme...
	 */
	if(start && (n = colon - start) && !isdigit((unsigned char) *start)
	   && (((n == 2
		 && (*start == 'w' || *start == 'W')
		 && (*(start+1) == 's' || *(start+1) == 'S'))
		|| (n == 3
		 && (((*start == 'F' || *start == 'f')
		 	&& !struncmp(start+1, "tp", 2))
		     ||
		    ((*start == 'w' || *start == 'W')
		 	&& !struncmp(start+1, "ss", 2))))
		|| (n == 4
		    && (((*start == 'H' || *start == 'h') 
			 && !struncmp(start + 1, "ttp", 3))
			|| ((*start == 'N' || *start == 'n')
			    && !struncmp(start + 1, "ews", 3))
			|| ((*start == 'N' || *start == 'n')
			    && !struncmp(start + 1, "ntp", 3))
			|| ((*start == 'W' || *start == 'w')
			    && !struncmp(start + 1, "ais", 3))
#ifdef	ENABLE_LDAP
			|| ((*start == 'L' || *start == 'l')
			    && !struncmp(start + 1, "dap", 3))
#endif
			|| ((*start == 'I' || *start == 'i')
			    && !struncmp(start + 1, "map", 3))
			|| ((*start == 'F' || *start == 'f')
			    && !struncmp(start + 1, "ile", 3))))
		|| (n == 5
		    && (*start == 'H' || *start == 'h')
		    && !struncmp(start+1, "ttps", 4))
		|| (n == 6
		    && (((*start == 'G' || *start == 'g')
			 && !struncmp(start+1, "opher", 5))
			|| ((*start == 'M' || *start == 'm')
			    && !struncmp(start + 1, "ailto", 5))
			|| ((*start == 'T' || *start == 't')
			    && !struncmp(start + 1, "elnet", 5))))
		|| (n == 8
		    && (*start == 'P' || *start == 'p')
		    && !struncmp(start + 1, "rospero", 7))
		|| (n == 11
		    && (*start == 'x' || *start == 'X')
		    && !struncmp(start + 1, "-pine-help", 10))
		|| (n == 13
		    && (*start == 'x' || *start == 'X')
		    && !struncmp(start + 1, "-alpine-help", 12)))
	       || url_external_specific_handler(start, n))){
		/*
		 * Second, make sure that everything to the right of the
		 * colon is valid for a "schemepart"...
		 */

	    if((end = rfc1738_scheme_part(colon + 1)) - colon > 1){
		int i, j;

		/* make sure something useful follows colon */
		for(i = 0, j = end - colon; i < j; i++)
		  if(!strchr(RFC1738_RSVP, colon[i]))
		    break;

		if(i != j){
		    *len = end - start;

		    /*
		     * Special case handling for comma.
		     * See the problem is comma's valid, but if it's the
		     * last character in the url, it's likely intended
		     * as a delimiter in the text rather part of the URL.
		     * In most cases any way, that's why we have the
		     * exception.
		     */
		    if(*(end - 1) == ','
		       || (*(end - 1) == '.' && (!*end  || *end == ' ')))
		      (*len)--;

		    if(*len - (colon - start) > 0)
		      return(start);
		}
	    }
	}
    }

    return(NULL);
}
/*
 * Dialog proc to handle login
 * 
 * Configures the dialog box on init and retrieves the settings on exit.
 */    
BOOL CALLBACK  __export 
config_vars_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    DLG_CONFIGVARSDATA *dlgcv;
    BOOL ret = FALSE;
    int usepop = 0;
    char buf[2*MAXPATH+1], *p;
    int buflen = 2*MAXPATH;
#define TCBUFLEN (2*MAXPATH)
    TCHAR tcbuf[TCBUFLEN+1];
    LPTSTR tmp_lptstr;
    char *u;

    switch (uMsg) {
      case WM_INITDIALOG:
  	dlgcv = (DLG_CONFIGVARSDATA *)lParam;
  	SetWindowLong (hDlg, WINDOW_USER_DATA, (LONG) dlgcv);
	if(dlgcv->ivars->pname){
	    tmp_lptstr = utf8_to_lptstr(dlgcv->ivars->pname);
	    if(tmp_lptstr){
		SetDlgItemText(hDlg, IDC_CFV_PNAME, tmp_lptstr);
		fs_give((void **) &tmp_lptstr);
	    }
	}

	if(dlgcv->ivars->userid && dlgcv->ivars->domain){
	    snprintf(buf, sizeof(buf), "%.*s@%.*s", MAXPATH, dlgcv->ivars->userid,
		    MAXPATH, dlgcv->ivars->domain);
	    buf[buflen-1] = '\0';
	    tmp_lptstr = utf8_to_lptstr(buf);
	    if(tmp_lptstr){
		SetDlgItemText(hDlg, IDC_CFV_EMAILADR, tmp_lptstr);
		fs_give((void **) &tmp_lptstr);
	    }
	}

	if(dlgcv->ivars->inboxpath){
	    char *mbx;

	    mbx = dlgcv->ivars->inboxpath;
	    if(*mbx == '{' && (p = strindex(mbx, '}'))
	       && ((*(p+1) == '\0') || !strucmp(p+1, "inbox"))){
		char srvbuf[MAXPATH+1], tuser[MAXPATH+1];
		int i, j, k;

		srvbuf[0] = '\0';
		tuser[0] = '\0';
		strncpy(buf, mbx+1, min(buflen, (int)(p - (mbx+1))));
		buf[min(buflen-1, (int)(p - (mbx+1)))] = '\0';
		for(i = 0, j = 0; buf[i] && j < MAXPATH; i++){
		    if(buf[i] == '/'){
			if(!struncmp("/user="******"/pop3", buf+i, 5)
				&& (!*(buf+5) || (*(buf+5) == '/'))){
			    usepop = 1;
			    i += 4;
			}
			else
			  srvbuf[j++] = buf[i];
		    }
		    else
		      srvbuf[j++] = buf[i];
		}
		srvbuf[j] = '\0';
		if(*srvbuf){
		    tmp_lptstr = utf8_to_lptstr(srvbuf);
		    if(tmp_lptstr){
			SetDlgItemText(hDlg, IDC_CFV_MSERVER, tmp_lptstr);
			fs_give((void **) &tmp_lptstr);
		    }
		}

		if(*tuser){
		    tmp_lptstr = utf8_to_lptstr(tuser);
		    if(tmp_lptstr){
			SetDlgItemText(hDlg, IDC_CFV_LOGIN, tmp_lptstr);
			fs_give((void **) &tmp_lptstr);
		    }
		}
	    }
	    else {
		tmp_lptstr = utf8_to_lptstr(mbx);
		if(tmp_lptstr){
		    SetDlgItemText(hDlg, IDC_CFV_MSERVER, tmp_lptstr);
		    fs_give((void **) &tmp_lptstr);
		}

		if(*mbx != '{' && *mbx != '#')
		  EnableWindow(GetDlgItem(hDlg, IDC_CFV_MSERVER), 0);
	    }
	}
	CheckRadioButton (hDlg, IDC_CFV_IMAP, IDC_CFV_POP3,
			  usepop ? IDC_CFV_POP3 : IDC_CFV_IMAP);
	if(dlgcv->ivars->smtpserver){
	    tmp_lptstr = utf8_to_lptstr(dlgcv->ivars->smtpserver);
	    if(tmp_lptstr){
		SetDlgItemText(hDlg, IDC_CFV_SMTPSERVER, tmp_lptstr);
		fs_give((void **) &tmp_lptstr);
	    }
	}

	if(dlgcv->ivars->defmailclient)
	  CheckDlgButton(hDlg, IDC_CFV_DEFMAILER, BST_CHECKED);
	if(dlgcv->ivars->defnewsclient)
	  CheckDlgButton(hDlg, IDC_CFV_DEFNEWSRDR, BST_CHECKED);
	
 	return (1);
	break;

      case WM_COMMAND:
	dlgcv = (DLG_CONFIGVARSDATA *) GetWindowLong (hDlg, WINDOW_USER_DATA);
	switch (wParam) {
	  case IDOK:
	    /* personal name */
	    GetDlgItemText(hDlg, IDC_CFV_PNAME, tcbuf, TCBUFLEN);
	    tcbuf[TCBUFLEN] = '\0';
	    u = lptstr_to_utf8(tcbuf);
	    if(u){
		removing_leading_and_trailing_white_space(u);
		if(dlgcv->ivars->pname)
		  fs_give((void **)&dlgcv->ivars->pname);

		if(*u){
		    dlgcv->ivars->pname = u;
		    u = NULL;
		}

		if(u)
		  fs_give((void **) &u);
	    }
	    
	    /* user-id and domain */
	    GetDlgItemText(hDlg, IDC_CFV_EMAILADR, tcbuf, TCBUFLEN);
	    tcbuf[TCBUFLEN] = '\0';
	    u = lptstr_to_utf8(tcbuf);
	    if(u){
		removing_leading_and_trailing_white_space(u);
		if(p = strindex(u, '@')){
		    *(p++) = '\0';
		    if(dlgcv->ivars->userid)
		      fs_give((void **)&dlgcv->ivars->userid);

		    if(dlgcv->ivars->domain)
		      fs_give((void **)&dlgcv->ivars->domain);

		    if(*u){
			dlgcv->ivars->userid = u;
			u = NULL;
		    }

		    if(*p)
		      dlgcv->ivars->domain = cpystr(p);
		}
		else{
		    MessageBox(hDlg, TEXT("Invalid email address.  Should be username@domain"),
			       TEXT("Alpine"), MB_ICONWARNING | MB_OK);
		    return(TRUE);
		}

		if(u)
		  fs_give((void **) &u);
	    }

	    /* inbox-path */
	    GetDlgItemText(hDlg, IDC_CFV_MSERVER, tcbuf, TCBUFLEN);
	    tcbuf[TCBUFLEN] = '\0';
	    u = lptstr_to_utf8(tcbuf);
	    if(u){
		removing_leading_and_trailing_white_space(u);
		if(*u == '{' || *u == '#'
		   || !IsWindowEnabled(GetDlgItem(hDlg, IDC_CFV_MSERVER))){
		    if(dlgcv->ivars->inboxpath)
		      fs_give((void **)&dlgcv->ivars->inboxpath);

		    dlgcv->ivars->inboxpath = u;
		    u = NULL;
		}
		else if(*u){
		    char tsrvr[4*MAXPATH+1];
		    int tsrvrlen = 4*MAXPATH;

		    if(dlgcv->ivars->inboxpath)
		      fs_give((void **)&dlgcv->ivars->inboxpath);

		    snprintf(tsrvr, sizeof(tsrvr), "{%s%s", u,
			    IsDlgButtonChecked(hDlg, IDC_CFV_POP3) 
			    == BST_CHECKED ? "/pop3" : "");

		    if(u)
		      fs_give((void **) &u);

		    GetDlgItemText(hDlg, IDC_CFV_LOGIN, tcbuf, TCBUFLEN);
		    tcbuf[TCBUFLEN] = '\0';
		    u = lptstr_to_utf8(tcbuf);
		    if(u){
			removing_leading_and_trailing_white_space(u);
			if(*u){
			    strncat(tsrvr, "/user="******"}inbox", sizeof(tsrvr)-strlen(tsrvr)-1);
			tsrvr[sizeof(tsrvr)-1] = '\0';
			dlgcv->ivars->inboxpath = cpystr(tsrvr);
		    }
		}

		if(u)
		  fs_give((void **) &u);
	    }

	    /* smtp-server */
	    GetDlgItemText(hDlg, IDC_CFV_SMTPSERVER, tcbuf, TCBUFLEN);
	    tcbuf[TCBUFLEN] = '\0';
	    u = lptstr_to_utf8(tcbuf);
	    if(u){
		removing_leading_and_trailing_white_space(u);
		if(dlgcv->ivars->smtpserver)
		  fs_give((void **)&dlgcv->ivars->smtpserver);

		if(*u){
		    dlgcv->ivars->smtpserver = u;
		    u = NULL;
		}

		if(u)
		  fs_give((void **) &u);
	    }

	    dlgcv->ivars->defmailclient =
	      (IsDlgButtonChecked(hDlg, IDC_CFV_DEFMAILER)
	       == BST_CHECKED);
	    dlgcv->ivars->defnewsclient =
	      (IsDlgButtonChecked(hDlg, IDC_CFV_DEFNEWSRDR)
	       == BST_CHECKED);

	    EndDialog (hDlg, LOWORD(wParam));
	    dlgcv->rv = 0;
	    ret = TRUE;
	    break;

	case IDCANCEL:
	    dlgcv->rv = 1;
	    ret = TRUE;
	    EndDialog (hDlg, LOWORD(wParam));
	    break;
        }
	break;
	

    }
    return (ret);
}
Beispiel #11
0
/*
 * Parse format_str and fill in disp_form structure based on what's there.
 *
 * Args: format_str -- The format string from pinerc.
 *        disp_form -- This is where we fill in the answer.
 *
 * The format string consists of special tokens which give the order of
 * the columns to be displayed.  The possible tokens are NICKNAME,
 * FULLNAME, ADDRESS, FCC, COMMENT.  If a token is followed by
 * parens with an integer inside (FULLNAME(16)) then that means we
 * make that variable that many characters wide.  If it is a percentage, we
 * allocate that percentage of the columns to that variable.  If no
 * parens, that means we calculate it for the user.  The tokens are
 * delimited by white space.  A token of DEFAULT means to calculate the
 * whole thing as we would if no spec was given.  This makes it possible
 * to specify default for one addrbook and something special for another.
 */
void
parse_format(char *format_str, COL_S *disp_form)
{
    int column = 0;
    char *p, *q;
    struct parse_tokens *pt;
    int nicknames, fullnames, addresses, not_allauto;
    int warnings = 0;

    p = format_str;
    while(p && *p && column < NFIELDS){
	p = skip_white_space(p);	/* space for next word */
    
	/* look for the ptoken this word matches */
	for(pt = ptokens; pt->name; pt++)
	    if(!struncmp(pt->name, p, strlen(pt->name)))
	      break;
	
	/* ignore unrecognized word */
	if(!pt->name){
	    char *r;

	    if((r=strindex(p, SPACE)) != NULL)
	      *r = '\0';

	    dprint((2, "parse_format: ignoring unrecognized word \"%s\" in address-book-formats\n", p ? p : "?"));
	    q_status_message1(SM_ORDER, warnings++==0 ? 1 : 0, 4,
		/* TRANSLATORS: an informative error message */
		_("Ignoring unrecognized word \"%s\" in Address-Book-Formats"), p);
	    /* put back space */
	    if(r)
	      *r = SPACE;

	    /* skip unrecognized word */
	    while(p && *p && !isspace((unsigned char)(*p)))
	      p++;

	    continue;
	}

	disp_form[column].type = pt->ctype;

	/* skip over name and look for parens */
	p += strlen(pt->name);
	if(*p == '('){
	    p++;
	    q = p;
	    while(p && *p && isdigit((unsigned char)*p))
	      p++;
	    
	    if(p && *p && *p == ')' && p > q){
		disp_form[column].wtype = Fixed;
		disp_form[column].req_width = atoi(q);
	    }
	    else if(p && *p && *p == '%' && p > q){
		disp_form[column].wtype = Percent;
		disp_form[column].req_width = atoi(q);
	    }
	    else{
		disp_form[column].wtype = WeCalculate;
		if(disp_form[column].type == Nickname)
		  disp_form[column].req_width = 8;
		else
		  disp_form[column].req_width = 3;
	    }
	}
	else{
	    disp_form[column].wtype     = WeCalculate;
	    if(disp_form[column].type == Nickname)
	      disp_form[column].req_width = 8;
	    else
	      disp_form[column].req_width = 3;
	}

	if(disp_form[column].type == Def){
	    /* If any type is DEFAULT, the widths are calculated old way */
assign_default:
	    column = 0;

	    disp_form[column].wtype  = AllAuto;
	    disp_form[column++].type = Nickname;
	    disp_form[column].wtype  = AllAuto;
	    disp_form[column++].type = Fullname;
	    disp_form[column].wtype  = AllAuto;
	    disp_form[column++].type = Addr;
	    /* Fill in rest */
	    while(column < NFIELDS)
	      disp_form[column++].type = Notused;

	    return;
	}

	column++;
	/* skip text at end of word */
	while(p && *p && !isspace((unsigned char)(*p)))
	  p++;
    }

    if(column == 0){
	q_status_message(SM_ORDER, 0, 4,
	_("Address-Book-Formats has no recognizable words, using default format"));
	goto assign_default;
    }

    /* Fill in rest */
    while(column < NFIELDS)
      disp_form[column++].type = Notused;

    /* check to see if user is just re-ordering default fields */
    nicknames = 0;
    fullnames = 0;
    addresses = 0;
    not_allauto = 0;
    for(column = 0; column < NFIELDS; column++){
	if(disp_form[column].type != Notused
	   && disp_form[column].wtype != WeCalculate)
	  not_allauto++;

	switch(disp_form[column].type){
	  case Nickname:
	    nicknames++;
	    break;

	  case Fullname:
	    fullnames++;
	    break;

	  case Addr:
	    addresses++;
	    break;

	  case Filecopy:
	  case Comment:
	    not_allauto++;
	    break;

	  default:
	    break;
	}
    }

    /*
     * Special case: if there is no address field specified, we put in
     * a special field called WhenNoAddrDisplayed, which causes list
     * entries to be displayable in all cases.
     */
    if(!addresses){
	for(column = 0; column < NFIELDS; column++)
	  if(disp_form[column].type == Notused)
	    break;
	
	if(column < NFIELDS){
	    disp_form[column].type  = WhenNoAddrDisplayed;
	    disp_form[column].wtype = Special;
	}
    }

    if(nicknames == 1 && fullnames == 1 && addresses == 1 && not_allauto == 0)
      disp_form[0].wtype = AllAuto; /* set to do default widths */
}