From 24364f9c9955ea10b094d6892e8c91d6b308ffe2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20Haslgr=C3=BCbler?= <work-michael@haslgruebler.eu>
Date: Wed, 21 Aug 2013 23:19:04 +0200
Subject: [PATCH 1/3] dovecot enchancement and bug fixes
* add mailbox to block_names
* fix for block_args in quotes
* fix for block's brackets upon write
* fixes broken tests for mailbox
* fixes indention
* test case for block_args with "
* fixes broken indention
(cherry picked from commit e6ff9449e5af1759d6b7828ceb118882e955dca4)
Use Quote module in dovecot
* use Quote.dquote_spaces for quoting
(cherry picked from commit 735caf587959019d214a51a7c0cce57da9bb88f6)
---
lenses/dovecot.aug | 37 +++++++++++++++++++++++++++++++++----
lenses/tests/test_dovecot.aug | 6 ++++++
2 files changed, 39 insertions(+), 4 deletions(-)
diff --git a/lenses/dovecot.aug b/lenses/dovecot.aug
index 6e5ccc9..e3558d0 100644
--- a/lenses/dovecot.aug
+++ b/lenses/dovecot.aug
@@ -56,9 +56,6 @@ let value = any . (Rx.space . any)*
(* View: command_start *)
let command_start = Util.del_str "!"
-(* View: block_args
-Map block arguments after block name and before "{" *)
-let block_args = Sep.space . store /[A-Za-z0-9\/\\_-]+/
(******************************************************************
* Group: ENTRIES
@@ -82,11 +79,43 @@ let entry = [ indent . key keys. eq . (Sep.opt_space . store value)? . eol ]
Map commands started with "!". *)
let command = [ command_start . key commands . Sep.space . store Rx.fspath . eol ]
+(*
+View: dquote_spaces
+ Make double quotes mandatory if value contains spaces,
+ and optional if value doesn't contain spaces.
+
+Based off Quote.dquote_spaces
+
+Parameters:
+ lns1:lens - the lens before
+ lns2:lens - the lens after
+*)
+let dquote_spaces (lns1:lens) (lns2:lens) =
+ (* bare has no spaces, and is optionally quoted *)
+ let bare = Quote.do_dquote_opt (store /[^" \t\n]+/)
+ (* quoted has at least one space, and must be quoted *)
+ in let quoted = Quote.do_dquote (store /[^"\n]*[ \t]+[^"\n]*/)
+ in [ lns1 . bare . lns2 ] | [ lns1 . quoted . lns2 ]
+
+let mailbox = indent
+ . dquote_spaces
+ (key /mailbox/ . Sep.space)
+ (Build.block_newlines (entry) comment . eol)
+
+let block_ldelim_newlines_re = /[ \t]+\{([ \t\n]*\n)?/
+
+let block_newlines (entry:lens) (comment:lens) =
+ let indent = del Rx.opt_space "\t"
+ in del block_ldelim_newlines_re Build.block_ldelim_default
+ . ((entry | comment) . (Util.empty | entry | comment)*)?
+ . del Build.block_rdelim_newlines_re Build.block_rdelim_newlines_default
+
(* View: block
Map block enclosed in brackets recursively.
Block may be indented and have optional argument.
Block body may have entries, comments, empty lines, and nested blocks recursively. *)
-let rec block = [ indent . key block_names . block_args? . Build.block_newlines (entry|block) comment . eol ]
+let rec block = [ indent . key block_names . (Sep.space . Quote.do_dquote_opt (store /[\/A-Za-z0-9_-]+/))? . block_newlines (entry|block|mailbox) comment . eol ]
+
(******************************************************************
* Group: LENS AND FILTER
diff --git a/lenses/tests/test_dovecot.aug b/lenses/tests/test_dovecot.aug
index 2201735..33ea16f 100644
--- a/lenses/tests/test_dovecot.aug
+++ b/lenses/tests/test_dovecot.aug
@@ -465,6 +465,9 @@ namespace {
hidden = no
list = yes
subscriptions = yes
+ mailbox \"Sent Messages\" {
+ special_use = \Sent
+ }
}
# Example shared namespace configuration
@@ -533,6 +536,9 @@ test Dovecot.lns get mail_conf =
{ "hidden" = "no" }
{ "list" = "yes" }
{ "subscriptions" = "yes" }
+ { "mailbox" = "Sent Messages"
+ { "special_use" = "\Sent" }
+ }
}
{ }
{ "#comment" = "Example shared namespace configuration" }
--
1.8.5.3