bbdb 0.5 → 0.6
raw patch · 5 files changed
+131/−88 lines, 5 filesdep +hspecdep −mtlPVP ok
version bump matches the API change (PVP)
Dependencies added: hspec
Dependencies removed: mtl
API changes (from Hackage documentation)
+ Database.BBDB: [creation] :: BBDB -> CreationDate
+ Database.BBDB: [hash] :: BBDB -> Hash
+ Database.BBDB: [modification] :: BBDB -> ModificationTime
+ Database.BBDB: type CreationDate = String
+ Database.BBDB: type Hash = String
+ Database.BBDB: type ModificationTime = String
- Database.BBDB: BBDB :: Maybe String -> Maybe String -> Maybe [String] -> Maybe [String] -> Maybe [String] -> Maybe [Phone] -> Maybe [Address] -> Maybe [String] -> Maybe Note -> BBDB
+ Database.BBDB: BBDB :: Maybe String -> Maybe String -> Maybe [String] -> Maybe [String] -> Maybe [String] -> Maybe [Phone] -> Maybe [Address] -> Maybe [String] -> Maybe Note -> Hash -> CreationDate -> ModificationTime -> BBDB
Files
- bbdb.cabal +27/−56
- changelog.md +7/−1
- src/Database/BBDB.hs +64/−31
- test/BBDBSpec.hs +32/−0
- test/Spec.hs +1/−0
bbdb.cabal view
@@ -1,70 +1,41 @@--- bbdb.cabal auto-generated by cabal init. For additional options,--- see--- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.--- The name of the package. Name: bbdb---- The package version. See the Haskell package versioning policy--- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for--- standards guiding when and how versions should be incremented.-Version: 0.5---- A short (one-line) description of the package.-Synopsis: Ability to read, write, and examine BBDB files---- A longer description of the package.--Description: BBDB (http://sourceforge.bbdb.net) is a contact management utility- that can be used with emacs. It stores its data internally as a lisp- expression. This module parses the lisp and provides some convenience- functions to get at and manipulate the data all from within Haskell.- See the hackage docs for usage and examples.---- URL for the project homepage or repository.-Homepage: http://www.nadineloveshenry.com/haskell/database-bbdb.html+Version: 0.6+Synopsis: Ability to read, write, and modify BBDB files+Description: BBDB (http://savannah.nongnu.org/projects/bbdb/) is a+ contact management utility that can be used with+ emacs. It stores its data internally as a lisp+ expression. This module parses the lisp and+ provides some convenience functions to get at and+ manipulate the data all from within Haskell. See+ the hackage docs for usage and examples. --- The license under which the package is released.+Homepage: https://github.com/henrylaxen/bbdb License: GPL-3---- The file containing the license text. License-file: LICENSE---- The package author(s). Author: Henry Laxen---- An email address to which users can send suggestions, bug reports,--- and patches.+Copyright: Henry Laxen Maintainer: nadine.and.henry@pobox.com---- A copyright notice.--- Copyright: -+Stability: stable+Bug-reports: mailto:nadine.and.henry@pobox.com Category: Database- Build-type: Simple---- Extra files to be distributed with the package, such as examples or--- a README. Extra-source-files: changelog.md---- Constraint on the version of Cabal needed to build this package.-Cabal-version: >=1.4-+Cabal-version: >=1.8 Library- -- Modules exported by the library. Exposed-modules: Database.BBDB hs-source-dirs: src- - -- Packages needed in order to build this package.- Build-depends: - base >= 3 && <= 5,- mtl,- parsec >=3+ Build-depends:+ base >= 3 && <= 5,+ parsec >=3+Test-Suite bbdb-tests+ Type: exitcode-stdio-1.0+ Main-is: Spec.hs+ hs-source-dirs: src,test+ Other-modules: Database.BBDB,+ BBDBSpec+ Build-depends:+ base >= 3 && <= 5,+ hspec,+ parsec >= 3 - -- Modules not exported by this package.- -- Other-modules: - - -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.- -- Build-tools: -
changelog.md view
@@ -1,7 +1,13 @@ Changes for Database/BBDB ========================= -From 0.4 -> 0.5+from 0.5 -> 0.6+The new BBDB version (BBDB3) uses file format 9 now. Three fields were+added: a hash field, a creation date field, and a modification time+field. Theses used to be present in the notes field.+++from 0.4 -> 0.5 --------------- The BBDB file format changed. The current version of the format
src/Database/BBDB.hs view
@@ -1,18 +1,19 @@-{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-} -- | -- This module can read and write BBDB files, and provides a few handy -- functions for getting at fields inside of BBDB data. -- --- BBDB (<http://bbdb.sourceforge.net/>) is short for the Insidious Big--- Brother Database, which is a contact management utility that can--- be integrated into Emacs (the one true editor.) Since bbdb.el is--- implemented in elisp, it can be difficult to \"get at\" the data--- inside a .bbdb file with external programs. Many years ago, I--- wrote a BBDB interface for perl, but having experience--- enlightenment at the hands of the category gods, I\`m now dabbling--- with Haskell. But having been a loyal Emacs user for many years--- now, I wanted a way to spam my friends while still using my--- favorite programming language. Hence the module Data.BBDB.+-- BBDB (now version 3) (<http://savannah.nongnu.org/projects/bbdb/>)+-- is short for the Insidious Big Brother Database, which is a contact+-- management utility that can be integrated into Emacs (the one true+-- editor.) Since bbdb.el is implemented in elisp, it can be+-- difficult to \"get at\" the data inside a .bbdb file with external+-- programs. Many years ago, I wrote a BBDB interface for perl, but+-- having experience enlightenment at the hands of the category gods,+-- I\`m now dabbling with Haskell. But having been a loyal Emacs user+-- for many years now, I wanted a way to spam my friends while still+-- using my favorite programming language. Hence the module+-- Data.BBDB. -- -- The following is the data layout for a BBDB record. I have created a -- sample record with my own data. Each field is just separated by a@@ -33,7 +34,7 @@ -- > "Reno" "Nevada" "89503" "USA" for City, State, Zip Code, and country -- > ] -- > ["home" another Address field--- > ("Via Alta #6" "Gaviotas #10") The street list+-- > ("Villa Alta #6" "Gaviotas #10") The street list -- > "Chapala" "Jalisco" City State -- > "45900" "Mexico" Zip and country -- > ]) @@ -43,10 +44,12 @@ -- > ) -- > ( -- > (notes . "Always split aces and eights") The notes field - a list of alists--- > (creation-date . "2010-09-03") --- > (timestamp . "2010-09-03") -- > (birthday . "6/15")--- > ) +-- > )+-- > "169cc701-8754-45f5-aba8-c89c2dc60a49" The hash field based+-- > on names, organizations, akas, and emails+-- > "2010-09-03" The creation date+-- > "2017-11-06 13:58:33 +0000" The last modifcation time -- > nil The cache vector - always nil -- > ] -- @@ -59,9 +62,9 @@ -- \"Chapala\" \"Jalisco\" \"45900\" \"Mexico\"]) -- (\"nadine.and.henry\@pobox.com\" \"nadinelaxen\@pobox.com\") -- ((notes . \"Always split aces and eights\") --- (creation-date . \"2010-09-03\") --- (timestamp . \"2010-09-03\") (birthday . \"6/15\")) nil]---+-- (birthday . \"6/15\")) "169cc701-8754-45f5-aba8-c89c2dc60a49"+-- "2010-09-03" "2017-11-06 13:58:33 +0000" nil]+-- -- When parsed, this is represented inside Haskell as: -- -- > BBDBEntry@@ -88,9 +91,10 @@ -- > Just -- > (Note{unnote = -- > [("notes", "Always split aces and eights"),--- > ("creation-date", "2010-09-03"),--- > ("timestamp", "2010-09-03"), -- > ("birthday", "6/15")]})})]+-- > hash = "169cc701-8754-45f5-aba8-c89c2dc60a49",+-- > creation = "2010-09-03", +-- > modification = "2017-11-06 13:58:33 +0000" -- > module Database.BBDB @@ -105,6 +109,9 @@ BBDB(..), BBDBFile(..), LispAble(..),+ Hash,+ CreationDate,+ ModificationTime, bbdbDefault, key,value, parseBBDB,@@ -124,6 +131,7 @@ import Text.Parsec hiding ((<|>)) import Control.Applicative hiding (many) import Data.Maybe+import Data.List doubleQuoteChar :: Char doubleQuoteChar = '"'@@ -154,6 +162,14 @@ -- alphanumerics and the characters _ (underscore) and - (dash) type Symbol = String +-- | Since file-format 9, BBDB now includes there more fields, which+-- | are always present and used internally.+-- | Synonym for String+type Hash = String+-- | Synonym for String+type CreationDate = String+-- | Synonym for String+type ModificationTime = String -- | For some unknow reason, BBDB can have phones in two different -- formats. In /USStyle/, the phone is list of integers, in the form -- of Area code, Prefix, Number, and Extension. I don\'t bother to@@ -196,33 +212,39 @@ } deriving (Eq, Ord, Show) +-- | The record fields of the BBDB data type data BBDB = BBDB { -- | the first name. Why is this a Maybe? Because sometimes you just -- have a company, and not a specific first name - firstName :: Maybe String,- lastName :: Maybe String,+ firstName :: Maybe String,+ lastName :: Maybe String, -- | aka = Also Known As. Sometimes the same email address can match -- several users, so BBDB gives you the option of remembering -- different names for the same address- affix :: Maybe [String],- aka :: Maybe [String],+ affix :: Maybe [String],+ aka :: Maybe [String], -- | The company if any - company :: Maybe [String],+ company :: Maybe [String], -- | A list of phone numbers, either in US Style or International Style- phone :: Maybe [Phone],+ phone :: Maybe [Phone], -- | A list of addresses, keyed by location- address :: Maybe [Address],+ address :: Maybe [Address], -- | A list of email addresses. -- BBDB uses the first element of this field when you create a new email- net :: Maybe [String],+ net :: Maybe [String], -- | Any number of key, value pairs. Great for random data.- notes :: Maybe Note+ notes :: Maybe Note,+ hash :: Hash,+ creation :: CreationDate,+ modification :: ModificationTime } deriving (Eq, Ord, Show) +-- | A BBDB record containing no data bbdbDefault :: BBDB-bbdbDefault = BBDB Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing+bbdbDefault = BBDB Nothing Nothing Nothing Nothing Nothing Nothing+ Nothing Nothing Nothing "" "" "" -- | At the beginning of a BBDB file are a variable number of comments, which -- specify the encoding type and the version. We just ignore them.@@ -337,9 +359,16 @@ space noteS <- notesParser space+ hash <- quotedString+ space+ creation <- quotedString+ space+ modifcation <- quotedString+ space string "nil" char ']'- return $ BBDB firstName lastName affix aka company phoneS addresseS net noteS+ return $ BBDB firstName lastName affix aka company phoneS addresseS+ net noteS hash creation modifcation -- | The Parser for a BBDB file, as it is written on disk. If you@@ -452,12 +481,16 @@ asLisp x = surroundWith '[' ']' $ unwords [asLisp (firstName x), asLisp (lastName x),+ asLisp (affix x), asLisp (aka x), asLisp (company x), asLisp (phone x), asLisp (address x), asLisp (net x), asLisp (notes x),+ asLisp (Just (hash x)),+ asLisp (Just (creation x)),+ asLisp (Just (modification x)), "nil" ]
+ test/BBDBSpec.hs view
@@ -0,0 +1,32 @@+module BBDBSpec where++import Database.BBDB+import Test.Hspec++spec :: Spec+spec = do+ bbdbString <- runIO $ readFile "test/sampleData.txt"+ describe "Read BBDB file" $ do+ let+ Right bbdb = parseBBDB bbdbString+ b = justEntries bbdb+ me = head b+ it "can parse the sample file as a String" $ do+ (length bbdbString) `shouldBe` 942+ (length bbdb) `shouldBe` 4+ it "can write it back as a lisp string" $ do+ let w = asLisp bbdb+ w == bbdbString `shouldBe` True+ it "found my first name" $ do+ firstName me `shouldBe` (Just "Henry")+ it "found my email" $ do + net me `shouldBe` (Just ["nadine.and.henry@pobox.com"])+ it "found the tennis note" $ do+ getNote "tennis" me `shouldBe` (Just "chapala")+ it "did not find the xyzzy note" $ do+ getNote "xyzzy" me `shouldBe` Nothing+ it "found the generic record" $ do+ let+ wanted x = lastName x == Just "lastname"+ r = filterBBDB wanted bbdb+ length r `shouldBe` 1
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}