/*----------------------------------------------------------------------
       Can we display this type/subtype?

   Args: type       -- the MIME type to check
         subtype    -- the MIME subtype
         params     -- parameters
	 use_viewer -- tell caller he should run external viewer cmd to view

 Result: returns 1 if the type is displayable, 0 otherwise.
 Note: we always return 1 for type text and type message, but sometimes
       we set use_viewer and sometimes we don't.
 ----*/
mime_can_display(type, subtype, params, use_viewer)
int       type;
char      *subtype;
PARAMETER *params;
int       *use_viewer;
{
    int rv, match;
    PARAMETER *param;

    /*
     * Want to catch some builtin types here that we don't ever want to hand
     * off to mailcap, but give mailcap a crack at the rest.
     */
    switch(type){
      case TYPEMULTIPART:
	if(use_viewer)
	  *use_viewer = 0;
	return 1;

      case TYPETEXT:
	for(param = params; 
		    param != NULL && strucmp(param->attribute,"charset") != 0;
		    param = param->next)
	    ;/* do nothing */

	match =  match_charset(param != NULL ? param->value : NULL,
				       ps_global->VAR_CHAR_SET);
	/*
	 * This is kind of backwards.  match == 0 means that the charset is
	 * something we know how to display.
	 */
	if(match == 0){
	    if(use_viewer)
	      *use_viewer = 0;
	    return 1;
	}
	break;
    }

    /* give mailcap a crack at anything else */
    if(mailcap_can_display(type, subtype, params)){
	if(use_viewer)
	  *use_viewer = 1;
	rv = 1;
    }
    else{
	if(use_viewer)
	  *use_viewer = 0;

	switch(type){

	  /* if mailcap didn't want to handle these, we will */
	  case TYPETEXT:
	  case TYPEMESSAGE:
	    rv = 1;
	    break;

	  default:
	    rv = 0;
	    break;
	}
    }
    return(rv);
}


