ELinks 0.18.0
mailcap.c File Reference
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "elinks.h"
#include "config/options.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "mime/backend/common.h"
#include "mime/backend/mailcap.h"
#include "mime/mime.h"
#include "osdep/osdep.h"
#include "session/session.h"
#include "util/file.h"
#include "util/hash.h"
#include "util/lists.h"
#include "util/memory.h"
#include "util/string.h"
Include dependency graph for mailcap.c:

Data Structures

struct  mailcap_hash_item
 
struct  mailcap_entry
 

Macros

#define get_opt_mailcap(which)   mailcap_options[(which)].option
 
#define get_mailcap(which)   get_opt_mailcap(which).value
 
#define get_mailcap_ask()   get_mailcap(MAILCAP_ASK).number
 
#define get_mailcap_description()   get_mailcap(MAILCAP_DESCRIPTION).number
 
#define get_mailcap_enable()   get_mailcap(MAILCAP_ENABLE).number
 
#define get_mailcap_prioritize()   get_mailcap(MAILCAP_PRIORITIZE).number
 
#define get_mailcap_path()   get_mailcap(MAILCAP_PATH).string
 

Enumerations

enum  mailcap_option {
  MAILCAP_TREE , MAILCAP_ENABLE , MAILCAP_PATH , MAILCAP_ASK ,
  MAILCAP_DESCRIPTION , MAILCAP_PRIORITIZE , MAILCAP_OPTIONS
}
 

Functions

static void done_mailcap_entry (struct mailcap_entry *entry)
 
static struct mailcap_entryinit_mailcap_entry (char *command, int priority)
 
static void add_mailcap_entry (struct mailcap_entry *entry, char *type, int typelen)
 
static char * get_mailcap_field (char **next)
 
static char * get_mailcap_field_text (char *field)
 
static int parse_optional_fields (struct mailcap_entry *entry, char *line)
 
static void parse_mailcap_file (char *filename, unsigned int priority)
 
static struct hashinit_mailcap_map (void)
 
static void done_mailcap (struct module *module)
 
static int change_hook_mailcap (struct session *ses, struct option *current, struct option *changed)
 
static void init_mailcap (struct module *module)
 
static char * format_command (char *command, char *type, int copiousoutput)
 
static struct mailcap_entrycheck_entries (struct mailcap_hash_item *item)
 
static struct mailcap_entryget_mailcap_entry (char *type)
 
static void set_display (int xwin, int restore)
 Set or unset the DISPLAY environment variable before a mailcap check, or restore it afterwards.
 
static struct mime_handlerget_mime_handler_mailcap (char *type, int xwin)
 

Variables

static union option_info mailcap_options []
 
static struct hashmailcap_map = NULL
 
const struct mime_backend mailcap_mime_backend
 
struct module mailcap_mime_module
 

Macro Definition Documentation

◆ get_mailcap

#define get_mailcap ( which)    get_opt_mailcap(which).value

◆ get_mailcap_ask

#define get_mailcap_ask ( )    get_mailcap(MAILCAP_ASK).number

◆ get_mailcap_description

#define get_mailcap_description ( )    get_mailcap(MAILCAP_DESCRIPTION).number

◆ get_mailcap_enable

#define get_mailcap_enable ( )    get_mailcap(MAILCAP_ENABLE).number

◆ get_mailcap_path

#define get_mailcap_path ( )    get_mailcap(MAILCAP_PATH).string

◆ get_mailcap_prioritize

#define get_mailcap_prioritize ( )    get_mailcap(MAILCAP_PRIORITIZE).number

◆ get_opt_mailcap

#define get_opt_mailcap ( which)    mailcap_options[(which)].option

Enumeration Type Documentation

◆ mailcap_option

Enumerator
MAILCAP_TREE 
MAILCAP_ENABLE 
MAILCAP_PATH 
MAILCAP_ASK 
MAILCAP_DESCRIPTION 
MAILCAP_PRIORITIZE 
MAILCAP_OPTIONS 

Function Documentation

◆ add_mailcap_entry()

static void add_mailcap_entry ( struct mailcap_entry * entry,
char * type,
int typelen )
inlinestatic

◆ change_hook_mailcap()

static int change_hook_mailcap ( struct session * ses,
struct option * current,
struct option * changed )
static

◆ check_entries()

static struct mailcap_entry * check_entries ( struct mailcap_hash_item * item)
static

◆ done_mailcap()

static void done_mailcap ( struct module * module)
static

◆ done_mailcap_entry()

static void done_mailcap_entry ( struct mailcap_entry * entry)
inlinestatic

◆ format_command()

static char * format_command ( char * command,
char * type,
int copiousoutput )
static

◆ get_mailcap_entry()

static struct mailcap_entry * get_mailcap_entry ( char * type)
static

◆ get_mailcap_field()

static char * get_mailcap_field ( char ** next)
static

◆ get_mailcap_field_text()

static char * get_mailcap_field_text ( char * field)
static

◆ get_mime_handler_mailcap()

static struct mime_handler * get_mime_handler_mailcap ( char * type,
int xwin )
static

◆ init_mailcap()

static void init_mailcap ( struct module * module)
static

◆ init_mailcap_entry()

static struct mailcap_entry * init_mailcap_entry ( char * command,
int priority )
inlinestatic

◆ init_mailcap_map()

static struct hash * init_mailcap_map ( void )
static

◆ parse_mailcap_file()

static void parse_mailcap_file ( char * filename,
unsigned int priority )
static

◆ parse_optional_fields()

static int parse_optional_fields ( struct mailcap_entry * entry,
char * line )
inlinestatic

◆ set_display()

static void set_display ( int xwin,
int restore )
static

Set or unset the DISPLAY environment variable before a mailcap check, or restore it afterwards.

In a mailcap file, each entry can specify a test command that checks whether the entry is applicable to the user's environment. For example:

* audio/mpegurl; xmms %s; test=test "$DISPLAY" != ""
* 

This means the entry should be used only if the DISPLAY environment variable is not empty, i.e. there is an X display. In ELinks, check_entries() runs these test commands, so they inherit the environment variables of the master ELinks process. However, if the user is running ELinks on multiple terminals, then each slave ELinks process has its own environment variables, which may or may not include DISPLAY. Because the actual mailcap command may be run from a slave ELinks process and inherit the environment from it, any test command should also be run in the same environment.

This function does not fully implement the ideal described above. Instead, it only sets the DISPLAY environment variable as ":0" if the terminal has any X display at all, or unsets DISPLAY if not. This should be enough for most test commands seen in practice. After the test commands of mailcap entries have been run, this function must be called again to restore DISPLAY.

Todo
Retrieve all environment variables from the slave process and propagate them to the test commands. Actually, it might be best to fork the test commands from the slave process, so that they would also inherit the controlling tty. However, that would require changing the interlink protocol and might risk deadlocks or memory leaks if a slave terminates without responding.
Parameters
xwinWhether the terminal has an associated X display.
restoreIf this is 0, the function sets or clears DISPLAY, as described above. If this is 1, the function restores the original value of DISPLAY. There is only room for one saved value; do not nest calls.

Variable Documentation

◆ mailcap_map

struct hash* mailcap_map = NULL
static

◆ mailcap_mime_backend

const struct mime_backend mailcap_mime_backend
Initial value:
= {
}
#define NULL
Definition explodename.c:35
static struct mime_handler * get_mime_handler_mailcap(char *type, int xwin)
Definition mailcap.c:743

◆ mailcap_mime_module

struct module mailcap_mime_module
Initial value:
N_("Mailcap"),
)
#define N_(msg)
Definition libintl.h:25
static union option_info mailcap_options[]
Definition mailcap.c:88
static void init_mailcap(struct module *module)
Definition mailcap.c:475
static void done_mailcap(struct module *module)
Definition mailcap.c:435
#define struct_module(name, options, hooks, submods, data, init, done, getname)
Definition module.h:47

◆ mailcap_options

union option_info mailcap_options[]
static