getTesterEmailAddresses <- function() {
     list(
           to  =  c(rick  = "rsaporta@theorchard.com"
                 ,  to01  = "tester.rs.to01@gmail.com"
                 ,  to02  = "tester.rs.to02@gmail.com")
         , cc  =  c(cc    = "tester.rs.cc@gmail.com"
                 ,  cc02  = "tester.rs.cc02@gmail.com")
         , bcc =  c(bcc   = "tester.rs.bcc@gmail.com"
                 ,  bcc02 = "tester.rs.bcc02@gmail.com")
          )
}

.testEmail <- function(subject="This is a test", msg="This is the body of the test email\nNew Line\n\nlast line of body", ...) {
     args <- collectArgs()
     testers <- getTesterEmailAddresses()
     for (x in c("to", "cc", "bcc"))
          if (x %ni% names(args))
               args[[x]] <- testers[[x]]
     do.call(email, args)
}

if (FALSE)
.testEmail(bcc=c(bcc   = "tester.rs.bcc@gmail.com"))

getRS <- function(adr=c("to", "cc", "bcc", "gmail")) {
     adr <- match.arg(adr)
     if (adr == "to")
          "Rick Saporta <rsaporta@theorchard.com>"
     else if (adr == "cc")
          "Rick Saporta <rsaporta+cc@theorchard.com>"
     else if (adr == "bcc")
          "Rick Saporta <rsaporta+bcc@theorchard.com>"
     else if (adr == "gmail")
          "Rick Saporta <rsaporta@gmail.com>"
     else 
          ""
}

getToGroup <- function(group_name="Rick All") {
  if (!length(group_name))
    stop("group_name must have length at least one")
  if (!is.character(group_name))
    stop("group_name must be a string")

  addresses <- 
     list(
            rick_all  = c("Rick Saporta (gmail)"="rsaporta@gmail.com", "Rick Saporta"="rsaporta@theorchard.com")
          , youtube   = c(
                             "Albina Binyaminova"  = "albina@theorchard.com"
                          ,          "Mike Baldo"  = "mbaldo@theorchard.com"
                          ,  "Gabriella Cantwell"  = "gcantwell@theorchard.com"
                          ,        "Kevin McAdoo"  = "kmcadoo@theorchard.com"
                        )
     )

  ## Clean up group_name
  group_name %<>% tolower %>% gsub(" ", "_", .)
  if (group_name == "yt")
    group_name <- "youtube"

  ## Sanity Check
  if (!all(group_name %in% names(addresses)))
    stop("Not all values of group_name are valid.\nAcceptable (valid) values are:\n\t", pasteC(names(addresses), C="\n\t"))
  

  ## Take a simplifed list or a list with more than one element
  ret <- if (length(group_name) > 1) addresses[group_name] else addresses[[group_name]]

  return(ret)
}

getTo <- function(adr=NULL) {
## Note: 'Data' defaults to dataRequests
## use   'DataA' for dataanalyticsdept


  addresses <- 
     list(
            smore  = c("Samantha Moore"="Samantha@theorchard.com")
          , smoore = c("Samantha Moore"="Samantha@theorchard.com")
          , nic    = c("Nicolas Rizzi"="nrizzi@theorchard.com")
          , mp     = c("Marissa Putney"="mputney@theorchard.com")
          , pras   = c("Prashant Bahadur"="prashant@theorchard.com")
          # , pras   = c("Prashant Bahadur"="prashant@theorchard.com")
          , lee    = c("Lee Westerfield"="lee@theorchard.com")
          , leon   = c("Leon Yin"="leon@theorchard.com")
          , gina   = c("Gina Soileau"="gsoileau@theorchard.com")
          , andi   = c("Andi Dardha"="adardha@theorchard.com")
          , dave   = c("Dave Suchmann"="dsuchmann@theorchard.com")
          , data               = c("Data Requests"="dataRequests@theorchard.com")
          , datarequests       = c("Data Requests"="dataRequests@theorchard.com")
          , dataanalytics      = c("Data Analytics Dept"="dataanalyticsdept@theorchard.com")
          , dataanalyticsdept  = c("Data Analytics Dept"="dataanalyticsdept@theorchard.com")
          , manning = c("Chris Manning"="cmanning@theorchard.com")
     )
  adr %<>% tolower
  
  if (!length(adr) || any(adr %ni% names(addresses)))
     stop ("adr '", adr, "'is not a known email address\n\nPossible address are:\n\t", pasteC(C="\n\t", sprintf("%10s :: %s <%s>", names(addresses), sapply(addresses, names), unlist(addresses))))

  return(unlist(unname(addresses[adr])))
}
