ELinks 0.16.1.1
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)
#define get_mailcap(which)
#define get_mailcap_ask()
#define get_mailcap_description()
#define get_mailcap_enable()
#define get_mailcap_prioritize()
#define get_mailcap_path()

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)
Value:
get_opt_mailcap(which).value
#define get_opt_mailcap(which)
Definition mailcap.c:125

◆ get_mailcap_ask

#define get_mailcap_ask ( )
Value:
#define get_mailcap(which)
Definition mailcap.c:126
@ MAILCAP_ASK
Definition mailcap.c:81

◆ get_mailcap_description

#define get_mailcap_description ( )
Value:
@ MAILCAP_DESCRIPTION
Definition mailcap.c:82

◆ get_mailcap_enable

#define get_mailcap_enable ( )
Value:
@ MAILCAP_ENABLE
Definition mailcap.c:79

◆ get_mailcap_path

#define get_mailcap_path ( )
Value:
@ MAILCAP_PATH
Definition mailcap.c:80

◆ get_mailcap_prioritize

#define get_mailcap_prioritize ( )
Value:
@ MAILCAP_PRIORITIZE
Definition mailcap.c:83

◆ get_opt_mailcap

#define get_opt_mailcap ( which)
Value:
#define option
Definition options.h:17
static union option_info mailcap_options[]
Definition mailcap.c:88

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()

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

◆ change_hook_mailcap()

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

◆ check_entries()

struct mailcap_entry * check_entries ( struct mailcap_hash_item * item)
static

◆ done_mailcap()

void done_mailcap ( struct module * module)
static

◆ done_mailcap_entry()

void done_mailcap_entry ( struct mailcap_entry * entry)
inlinestatic

◆ format_command()

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

◆ get_mailcap_entry()

struct mailcap_entry * get_mailcap_entry ( char * type)
static

◆ get_mailcap_field()

char * get_mailcap_field ( char ** next)
static

◆ get_mailcap_field_text()

char * get_mailcap_field_text ( char * field)
static

◆ get_mime_handler_mailcap()

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

◆ init_mailcap()

void init_mailcap ( struct module * module)
static

◆ init_mailcap_entry()

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

◆ init_mailcap_map()

struct hash * init_mailcap_map ( void )
static

◆ parse_mailcap_file()

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

◆ parse_optional_fields()

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

◆ set_display()

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:733

◆ mailcap_mime_module

struct module mailcap_mime_module
Initial value:
N_("Mailcap"),
)
#define N_(msg)
Definition libintl.h:25
static void init_mailcap(struct module *module)
Definition mailcap.c:465
static void done_mailcap(struct module *module)
Definition mailcap.c:425
#define struct_module(name, options, hooks, submods, data, init, done)
Definition module.h:44

◆ mailcap_options

union option_info mailcap_options[]
static