Some miscellaneous functions. More...
#include "config.h"
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <pwd.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "alias/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "muttlib.h"
#include "enter/lib.h"
#include "ncrypt/lib.h"
#include "parse/lib.h"
#include "question/lib.h"
#include "format_flags.h"
#include "globals.h"
#include "hook.h"
#include "mx.h"
#include "protos.h"
#include "imap/lib.h"
Go to the source code of this file.
Functions | |
void | mutt_adv_mktemp (struct Buffer *buf) |
Create a temporary file. More... | |
char * | mutt_expand_path (char *buf, size_t buflen) |
Create the canonical path. More... | |
void | buf_expand_path_regex (struct Buffer *buf, bool regex) |
Create the canonical path (with regex char escaping) More... | |
void | buf_expand_path (struct Buffer *buf) |
Create the canonical path. More... | |
char * | mutt_expand_path_regex (char *buf, size_t buflen, bool regex) |
Create the canonical path (with regex char escaping) More... | |
char * | mutt_gecos_name (char *dest, size_t destlen, struct passwd *pw) |
Lookup a user's real name in /etc/passwd. More... | |
bool | mutt_needs_mailcap (struct Body *m) |
Does this type need a mailcap entry do display. More... | |
bool | mutt_is_text_part (struct Body *b) |
Is this part of an email in plain text? More... | |
void | mutt_pretty_mailbox (char *buf, size_t buflen) |
Shorten a mailbox path using '~' or '='. More... | |
void | buf_pretty_mailbox (struct Buffer *buf) |
Shorten a mailbox path using '~' or '='. More... | |
int | mutt_check_overwrite (const char *attname, const char *path, struct Buffer *fname, enum SaveAttach *opt, char **directory) |
Ask the user if overwriting is necessary. More... | |
void | mutt_save_path (char *buf, size_t buflen, const struct Address *addr) |
Turn an email address into a filename (for saving) More... | |
void | buf_save_path (struct Buffer *dest, const struct Address *a) |
Make a safe filename from an email address. More... | |
void | mutt_safe_path (struct Buffer *dest, const struct Address *a) |
Make a safe filename from an email address. More... | |
void | mutt_expando_format (char *buf, size_t buflen, size_t col, int cols, const char *src, format_t callback, intptr_t data, MuttFormatFlags flags) |
Expand expandos (x) in a string -. More... | |
FILE * | mutt_open_read (const char *path, pid_t *thepid) |
Run a command to read from. More... | |
int | mutt_save_confirm (const char *s, struct stat *st) |
Ask the user to save. More... | |
void | mutt_sleep (short s) |
Sleep for a while. More... | |
const char * | mutt_make_version (void) |
Generate the NeoMutt version string. More... | |
void | mutt_encode_path (struct Buffer *buf, const char *src) |
Convert a path to 'us-ascii'. More... | |
int | mutt_set_xdg_path (enum XdgType type, struct Buffer *buf) |
Find an XDG path or its fallback. More... | |
void | mutt_get_parent_path (const char *path, char *buf, size_t buflen) |
Find the parent of a path (or mailbox) More... | |
int | mutt_inbox_cmp (const char *a, const char *b) |
Do two folders share the same path and one is an inbox. More... | |
void | buf_sanitize_filename (struct Buffer *buf, const char *path, short slash) |
Replace unsafe characters in a filename. More... | |
void | mutt_str_pretty_size (char *buf, size_t buflen, size_t num) |
Display an abbreviated size, like 3.4K. More... | |
void | add_to_stailq (struct ListHead *head, const char *str) |
Add a string to a list. More... | |
void | remove_from_stailq (struct ListHead *head, const char *str) |
Remove an item, matching a string, from a List. More... | |
Variables | |
static const char * | XdgEnvVars [] |
Accepted XDG environment variables. More... | |
static const char * | XdgDefaults [] |
XDG default locations. More... | |
Some miscellaneous functions.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file muttlib.c.
void mutt_adv_mktemp | ( | struct Buffer * | buf | ) |
Create a temporary file.
buf | Buffer for the name |
Accept a "suggestion" for file name. If that file exists, then construct one with unique name but keep any extension. This might fail, I guess.
Definition at line 85 of file muttlib.c.
char * mutt_expand_path | ( | char * | buf, |
size_t | buflen | ||
) |
Create the canonical path.
buf | Buffer with path |
buflen | Length of buffer |
ptr | The expanded string |
Definition at line 124 of file muttlib.c.
void buf_expand_path_regex | ( | struct Buffer * | buf, |
bool | regex | ||
) |
Create the canonical path (with regex char escaping)
buf | Buffer with path |
regex | If true, escape any regex characters |
Definition at line 136 of file muttlib.c.
void buf_expand_path | ( | struct Buffer * | buf | ) |
Create the canonical path.
buf | Buffer with path |
Definition at line 333 of file muttlib.c.
char * mutt_expand_path_regex | ( | char * | buf, |
size_t | buflen, | ||
bool | regex | ||
) |
Create the canonical path (with regex char escaping)
buf | Buffer with path |
buflen | Length of buffer |
regex | If true, escape any regex characters |
ptr | The expanded string |
Definition at line 347 of file muttlib.c.
char * mutt_gecos_name | ( | char * | dest, |
size_t | destlen, | ||
struct passwd * | pw | ||
) |
Lookup a user's real name in /etc/passwd.
dest | Buffer for the result |
destlen | Length of buffer |
pw | Passwd entry |
ptr | Result buffer on success |
Extract the real name from /etc/passwd's GECOS field. When set, honor the regular expression in $gecos_mask
, otherwise assume that the GECOS field is a comma-separated list. Replace "&" by a capitalized version of the user's login name.
Definition at line 372 of file muttlib.c.
bool mutt_needs_mailcap | ( | struct Body * | m | ) |
Does this type need a mailcap entry do display.
m | Attachment body to be displayed |
true | NeoMutt requires a mailcap entry to display |
false | otherwise |
Definition at line 420 of file muttlib.c.
bool mutt_is_text_part | ( | struct Body * | b | ) |
Is this part of an email in plain text?
b | Part of an email |
true | Part is in plain text |
Definition at line 448 of file muttlib.c.
void mutt_pretty_mailbox | ( | char * | buf, |
size_t | buflen | ||
) |
Shorten a mailbox path using '~' or '='.
buf | Buffer containing string to shorten |
buflen | Length of buffer |
Collapse the pathname using ~ or = when possible
Definition at line 481 of file muttlib.c.
void buf_pretty_mailbox | ( | struct Buffer * | buf | ) |
Shorten a mailbox path using '~' or '='.
Definition at line 560 of file muttlib.c.
int mutt_check_overwrite | ( | const char * | attname, |
const char * | path, | ||
struct Buffer * | fname, | ||
enum SaveAttach * | opt, | ||
char ** | directory | ||
) |
Ask the user if overwriting is necessary.
[in] | attname | Attachment name |
[in] | path | Path to save the file |
[out] | fname | Buffer for filename |
[out] | opt | Save option, see SaveAttach |
[out] | directory | Directory to save under (OPTIONAL) |
0 | Success |
-1 | Abort |
1 | Error |
Definition at line 582 of file muttlib.c.
void mutt_save_path | ( | char * | buf, |
size_t | buflen, | ||
const struct Address * | addr | ||
) |
Turn an email address into a filename (for saving)
If the user hasn't set $save_address
the name will be truncated to the '@' character.
Definition at line 668 of file muttlib.c.
Make a safe filename from an email address.
Definition at line 693 of file muttlib.c.
Make a safe filename from an email address.
The filename will be stripped of '/', space, etc to make it safe.
Definition at line 723 of file muttlib.c.
FILE * mutt_open_read | ( | const char * | path, |
pid_t * | thepid | ||
) |
Run a command to read from.
[in] | path | Path to command |
[out] | thepid | PID of the command |
ptr | File containing output of command |
This function allows the user to specify a command to read stdout from in place of a normal file. If the last character in the string is a pipe (|), then we assume it is a command to run instead of a normal file.
Definition at line 1280 of file muttlib.c.
int mutt_save_confirm | ( | const char * | s, |
struct stat * | st | ||
) |
Ask the user to save.
s | Save location |
st | Timestamp |
0 | OK to proceed |
-1 | to abort |
1 | to retry |
Definition at line 1325 of file muttlib.c.
void mutt_sleep | ( | short | s | ) |
Sleep for a while.
s | Number of seconds to sleep |
If the user config '$sleep_time' is larger, sleep that long instead.
Definition at line 1424 of file muttlib.c.
const char * mutt_make_version | ( | void | ) |
void mutt_encode_path | ( | struct Buffer * | buf, |
const char * | src | ||
) |
Convert a path to 'us-ascii'.
buf | Buffer for the result |
src | Path to convert (OPTIONAL) |
If src
is NULL, the path in buf
will be converted in-place.
Definition at line 1453 of file muttlib.c.
Find an XDG path or its fallback.
type | Type of XDG variable, e.g. XDG_CONFIG_HOME |
buf | Buffer to save path |
1 | An entry was found that actually exists on disk and 0 otherwise |
Process an XDG environment variable or its fallback.
Definition at line 1478 of file muttlib.c.
void mutt_get_parent_path | ( | const char * | path, |
char * | buf, | ||
size_t | buflen | ||
) |
Find the parent of a path (or mailbox)
path | Path to use |
buf | Buffer for the result |
buflen | Length of buffer |
Definition at line 1517 of file muttlib.c.
int mutt_inbox_cmp | ( | const char * | a, |
const char * | b | ||
) |
Do two folders share the same path and one is an inbox.
a | First path |
b | Second path |
-1 | a is INBOX of b |
0 | None is INBOX |
1 | b is INBOX for a |
This function compares two folder paths. It first looks for the position of the last common '/' character. If a valid position is found and it's not the last character in any of the two paths, the remaining parts of the paths are compared (case insensitively) with the string "INBOX". If one of the two paths matches, it's reported as being less than the other and the function returns -1 (a < b) or 1 (a > b). If no paths match the requirements, the two paths are considered equivalent and this function returns 0.
Examples:
Definition at line 1579 of file muttlib.c.
void buf_sanitize_filename | ( | struct Buffer * | buf, |
const char * | path, | ||
short | slash | ||
) |
Replace unsafe characters in a filename.
Definition at line 1625 of file muttlib.c.
void mutt_str_pretty_size | ( | char * | buf, |
size_t | buflen, | ||
size_t | num | ||
) |
Display an abbreviated size, like 3.4K.
buf | Buffer for the result |
buflen | Length of the buffer |
num | Number to abbreviate |
Definition at line 1647 of file muttlib.c.
void add_to_stailq | ( | struct ListHead * | head, |
const char * | str | ||
) |
Add a string to a list.
head | String list |
str | String to add |
Definition at line 1693 of file muttlib.c.
void remove_from_stailq | ( | struct ListHead * | head, |
const char * | str | ||
) |
Remove an item, matching a string, from a List.
head | Head of the List |
str | String to match |
Definition at line 1718 of file muttlib.c.
|
static |
Accepted XDG environment variables.
|
static |
XDG default locations.