#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "mutt/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "format_flags.h"
#include "hook.h"
#include "mutt_commands.h"
#include "mutt_globals.h"
#include "muttlib.h"
#include "mx.h"
#include "protos.h"
Go to the source code of this file.
Functions | |
void | mutt_comp_init (void) |
Setup feature commands. More... | |
static bool | lock_realpath (struct Mailbox *m, bool excl) |
Try to lock the ctx->realpath. More... | |
static void | unlock_realpath (struct Mailbox *m) |
Unlock the mailbox->realpath. More... | |
static int | setup_paths (struct Mailbox *m) |
Set the mailbox paths. More... | |
static void | store_size (const struct Mailbox *m) |
Save the size of the compressed file. More... | |
static struct CompressInfo * | set_compress_info (struct Mailbox *m) |
Find the compress hooks for a mailbox. More... | |
static void | compress_info_free (struct Mailbox *m) |
Frees the compress info members and structure. More... | |
static const char * | compress_format_str (char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags) |
Expand the filenames in a command string - Implements format_t. More... | |
static void | expand_command_str (const struct Mailbox *m, const char *cmd, char *buf, int buflen) |
Expand placeholders in command string. More... | |
static int | execute_command (struct Mailbox *m, const char *command, const char *progress) |
Run a system command. More... | |
bool | mutt_comp_can_append (struct Mailbox *m) |
Can we append to this path? More... | |
bool | mutt_comp_can_read (const char *path) |
Can we read from this file? More... | |
int | mutt_comp_valid_command (const char *cmd) |
Is this command string allowed? More... | |
static bool | comp_ac_owns_path (struct Account *a, const char *path) |
Check whether an Account owns a Mailbox path - Implements MxOps::ac_owns_path() More... | |
static bool | comp_ac_add (struct Account *a, struct Mailbox *m) |
Add a Mailbox to an Account - Implements MxOps::ac_add() More... | |
static enum MxOpenReturns | comp_mbox_open (struct Mailbox *m) |
Open a Mailbox - Implements MxOps::mbox_open() More... | |
static bool | comp_mbox_open_append (struct Mailbox *m, OpenMailboxFlags flags) |
Open a Mailbox for appending - Implements MxOps::mbox_open_append() More... | |
static enum MxStatus | comp_mbox_check (struct Mailbox *m) |
Check for new mail - Implements MxOps::mbox_check() More... | |
static enum MxStatus | comp_mbox_sync (struct Mailbox *m) |
Save changes to the Mailbox - Implements MxOps::mbox_sync() More... | |
static enum MxStatus | comp_mbox_close (struct Mailbox *m) |
Close a Mailbox - Implements MxOps::mbox_close() More... | |
static bool | comp_msg_open (struct Mailbox *m, struct Message *msg, int msgno) |
Open an email message in a Mailbox - Implements MxOps::msg_open() More... | |
static bool | comp_msg_open_new (struct Mailbox *m, struct Message *msg, const struct Email *e) |
Open a new message in a Mailbox - Implements MxOps::msg_open_new() More... | |
static int | comp_msg_commit (struct Mailbox *m, struct Message *msg) |
Save changes to an email - Implements MxOps::msg_commit() More... | |
static int | comp_msg_close (struct Mailbox *m, struct Message *msg) |
Close an email - Implements MxOps::msg_close() More... | |
static int | comp_msg_padding_size (struct Mailbox *m) |
Bytes of padding between messages - Implements MxOps::msg_padding_size() More... | |
static int | comp_msg_save_hcache (struct Mailbox *m, struct Email *e) |
Save message to the header cache - Implements MxOps::msg_save_hcache() More... | |
static int | comp_tags_edit (struct Mailbox *m, const char *tags, char *buf, size_t buflen) |
Prompt and validate new messages tags - Implements MxOps::tags_edit() More... | |
static int | comp_tags_commit (struct Mailbox *m, struct Email *e, char *buf) |
Save the tags to a message - Implements MxOps::tags_commit() More... | |
static enum MailboxType | comp_path_probe (const char *path, const struct stat *st) |
Is this a compressed Mailbox? - Implements MxOps::path_probe() More... | |
static int | comp_path_canon (char *buf, size_t buflen) |
Canonicalise a Mailbox path - Implements MxOps::path_canon() More... | |
static int | comp_path_pretty (char *buf, size_t buflen, const char *folder) |
Abbreviate a Mailbox path - Implements MxOps::path_pretty() More... | |
static int | comp_path_parent (char *buf, size_t buflen) |
Find the parent of a Mailbox path - Implements MxOps::path_parent() More... | |
Variables | |
static const struct Command | comp_commands [] |
struct MxOps | MxCompOps |
Compressed Mailbox - Implements MxOps. More... | |
Compressed mbox local mailbox type
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 compress.c.
void mutt_comp_init | ( | void | ) |
Setup feature commands.
Definition at line 66 of file compress.c.
|
static |
Try to lock the ctx->realpath.
m | Mailbox to lock |
excl | Lock exclusively? |
true | Success (locked or readonly) |
false | Error (can't lock the file) |
Try to (exclusively) lock the mailbox. If we succeed, then we mark the mailbox as locked. If we fail, but we didn't want exclusive rights, then the mailbox will be marked readonly.
Definition at line 82 of file compress.c.
|
static |
Unlock the mailbox->realpath.
m | Mailbox to unlock |
Unlock a mailbox previously locked by lock_mailbox().
Definition at line 121 of file compress.c.
|
static |
Set the mailbox paths.
m | Mailbox to modify |
0 | Success |
-1 | Error |
Save the compressed filename in mailbox->realpath. Create a temporary filename and put its name in mailbox->path. The temporary file is created to prevent symlink attacks.
Definition at line 147 of file compress.c.
|
static |
Save the size of the compressed file.
m | Mailbox |
Save the compressed file size in the compress_info struct.
Definition at line 175 of file compress.c.
|
static |
Find the compress hooks for a mailbox.
m | Mailbox to examine |
ptr | CompressInfo Hook info for the mailbox's path |
NULL | Error |
When a mailbox is opened, we check if there are any matching hooks.
Definition at line 193 of file compress.c.
|
static |
Frees the compress info members and structure.
m | Mailbox to free compress_info for |
Definition at line 223 of file compress.c.
|
static |
Expand the filenames in a command string - Implements format_t.
Expando | Description |
---|---|
%f | Compressed file |
%t | Plaintext, temporary file |
Definition at line 246 of file compress.c.
|
static |
Expand placeholders in command string.
m | Mailbox for paths |
cmd | Template command to be expanded |
buf | Buffer to store the command |
buflen | Size of the buffer |
This function takes a hook command and expands the filename placeholders within it. The function calls mutt_expando_format() to do the replacement which calls our callback function compress_format_str(). e.g.
Template command: gzip -cd 'f' > 't'
Result: gzip -dc '~/mail/abc.gz' > '/tmp/xyz'
Definition at line 296 of file compress.c.
|
static |
Run a system command.
1 | Success |
0 | Failure |
Run the supplied command, taking care of all the NeoMutt requirements, such as locking files and blocking signals.
Definition at line 316 of file compress.c.
bool mutt_comp_can_append | ( | struct Mailbox * | m | ) |
Can we append to this path?
m | Mailbox |
true | Yes, we can append to the file |
false | No, appending isn't possible |
To append to a file we can either use an 'append-hook' or a combination of 'open-hook' and 'close-hook'.
A match means it's our responsibility to append to the file.
Definition at line 356 of file compress.c.
bool mutt_comp_can_read | ( | const char * | path | ) |
Can we read from this file?
path | Pathname of file to be tested |
true | Yes, we can read the file |
false | No, we can't read the file |
Search for an 'open-hook' with a regex that matches the path.
A match means it's our responsibility to open the file.
Definition at line 385 of file compress.c.
int mutt_comp_valid_command | ( | const char * | cmd | ) |
Is this command string allowed?
cmd | Command string |
1 | Valid command |
0 | "%f" and/or "%t" is missing |
A valid command string must have both "%f" (from file) and "%t" (to file). We don't check if we can actually run the command.
Definition at line 405 of file compress.c.
|
static |
Check whether an Account owns a Mailbox path - Implements MxOps::ac_owns_path()
Definition at line 416 of file compress.c.
Add a Mailbox to an Account - Implements MxOps::ac_add()
Definition at line 424 of file compress.c.
|
static |
Open a Mailbox - Implements MxOps::mbox_open()
Set up a compressed mailbox to be read. Decompress the mailbox and set up the paths and hooks needed. Then determine the type of the mailbox so we can delegate the handling of messages.
Definition at line 437 of file compress.c.
|
static |
Open a Mailbox for appending - Implements MxOps::mbox_open_append()
flags may also contain MUTT_NEWFOLDER
To append to a compressed mailbox we need an append-hook (or both open- and close-hooks).
Definition at line 495 of file compress.c.
Check for new mail - Implements MxOps::mbox_check()
m | Mailbox |
enum | MxStatus |
If the compressed file changes in size but the mailbox hasn't been changed in NeoMutt, then we can close and reopen the mailbox.
If the mailbox has been changed in NeoMutt, warn the user.
Definition at line 574 of file compress.c.
Save changes to the Mailbox - Implements MxOps::mbox_sync()
Changes in NeoMutt only affect the tmp file. Calling comp_mbox_sync() will commit them to the compressed file.
Definition at line 610 of file compress.c.
Close a Mailbox - Implements MxOps::mbox_close()
If the mailbox has been changed then re-compress the tmp file. Then delete the tmp file.
Definition at line 662 of file compress.c.
Open an email message in a Mailbox - Implements MxOps::msg_open()
Definition at line 728 of file compress.c.
|
static |
Open a new message in a Mailbox - Implements MxOps::msg_open_new()
Definition at line 746 of file compress.c.
Save changes to an email - Implements MxOps::msg_commit()
Definition at line 764 of file compress.c.
|
static |
Bytes of padding between messages - Implements MxOps::msg_padding_size()
Definition at line 800 of file compress.c.
Save message to the header cache - Implements MxOps::msg_save_hcache()
Definition at line 817 of file compress.c.
|
static |
Prompt and validate new messages tags - Implements MxOps::tags_edit()
Definition at line 834 of file compress.c.
Save the tags to a message - Implements MxOps::tags_commit()
Definition at line 851 of file compress.c.
|
static |
Is this a compressed Mailbox? - Implements MxOps::path_probe()
Definition at line 868 of file compress.c.
|
static |
Canonicalise a Mailbox path - Implements MxOps::path_canon()
Definition at line 882 of file compress.c.
|
static |
Abbreviate a Mailbox path - Implements MxOps::path_pretty()
Definition at line 891 of file compress.c.
|
static |
Find the parent of a Mailbox path - Implements MxOps::path_parent()
Definition at line 905 of file compress.c.
|
static |
Definition at line 55 of file compress.c.
struct MxOps MxCompOps |
Compressed Mailbox - Implements MxOps.
Compress only uses open, close and check. The message functions are delegated to mbox.
Definition at line 926 of file compress.c.