id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
148,100 | alecthomas/kingpin | values_generated.go | DurationList | func (p *parserMixin) DurationList() (target *[]time.Duration) {
target = new([]time.Duration)
p.DurationListVar(target)
return
} | go | func (p *parserMixin) DurationList() (target *[]time.Duration) {
target = new([]time.Duration)
p.DurationListVar(target)
return
} | [
"func",
"(",
"p",
"*",
"parserMixin",
")",
"DurationList",
"(",
")",
"(",
"target",
"*",
"[",
"]",
"time",
".",
"Duration",
")",
"{",
"target",
"=",
"new",
"(",
"[",
"]",
"time",
".",
"Duration",
")",
"\n",
"p",
".",
"DurationListVar",
"(",
"target",
")",
"\n",
"return",
"\n",
"}"
]
| // DurationList accumulates time.Duration values into a slice. | [
"DurationList",
"accumulates",
"time",
".",
"Duration",
"values",
"into",
"a",
"slice",
"."
]
| ef6e7c151c4fdbd3fe78aad001729fee08fa0932 | https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L617-L621 |
148,101 | alecthomas/kingpin | values_generated.go | IPList | func (p *parserMixin) IPList() (target *[]net.IP) {
target = new([]net.IP)
p.IPListVar(target)
return
} | go | func (p *parserMixin) IPList() (target *[]net.IP) {
target = new([]net.IP)
p.IPListVar(target)
return
} | [
"func",
"(",
"p",
"*",
"parserMixin",
")",
"IPList",
"(",
")",
"(",
"target",
"*",
"[",
"]",
"net",
".",
"IP",
")",
"{",
"target",
"=",
"new",
"(",
"[",
"]",
"net",
".",
"IP",
")",
"\n",
"p",
".",
"IPListVar",
"(",
"target",
")",
"\n",
"return",
"\n",
"}"
]
| // IPList accumulates net.IP values into a slice. | [
"IPList",
"accumulates",
"net",
".",
"IP",
"values",
"into",
"a",
"slice",
"."
]
| ef6e7c151c4fdbd3fe78aad001729fee08fa0932 | https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L630-L634 |
148,102 | alecthomas/kingpin | values_generated.go | ExistingFiles | func (p *parserMixin) ExistingFiles() (target *[]string) {
target = new([]string)
p.ExistingFilesVar(target)
return
} | go | func (p *parserMixin) ExistingFiles() (target *[]string) {
target = new([]string)
p.ExistingFilesVar(target)
return
} | [
"func",
"(",
"p",
"*",
"parserMixin",
")",
"ExistingFiles",
"(",
")",
"(",
"target",
"*",
"[",
"]",
"string",
")",
"{",
"target",
"=",
"new",
"(",
"[",
"]",
"string",
")",
"\n",
"p",
".",
"ExistingFilesVar",
"(",
"target",
")",
"\n",
"return",
"\n",
"}"
]
| // ExistingFiles accumulates string values into a slice. | [
"ExistingFiles",
"accumulates",
"string",
"values",
"into",
"a",
"slice",
"."
]
| ef6e7c151c4fdbd3fe78aad001729fee08fa0932 | https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L656-L660 |
148,103 | alecthomas/kingpin | values_generated.go | ExistingDirs | func (p *parserMixin) ExistingDirs() (target *[]string) {
target = new([]string)
p.ExistingDirsVar(target)
return
} | go | func (p *parserMixin) ExistingDirs() (target *[]string) {
target = new([]string)
p.ExistingDirsVar(target)
return
} | [
"func",
"(",
"p",
"*",
"parserMixin",
")",
"ExistingDirs",
"(",
")",
"(",
"target",
"*",
"[",
"]",
"string",
")",
"{",
"target",
"=",
"new",
"(",
"[",
"]",
"string",
")",
"\n",
"p",
".",
"ExistingDirsVar",
"(",
"target",
")",
"\n",
"return",
"\n",
"}"
]
| // ExistingDirs accumulates string values into a slice. | [
"ExistingDirs",
"accumulates",
"string",
"values",
"into",
"a",
"slice",
"."
]
| ef6e7c151c4fdbd3fe78aad001729fee08fa0932 | https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L669-L673 |
148,104 | alecthomas/kingpin | values_generated.go | ExistingFilesOrDirs | func (p *parserMixin) ExistingFilesOrDirs() (target *[]string) {
target = new([]string)
p.ExistingFilesOrDirsVar(target)
return
} | go | func (p *parserMixin) ExistingFilesOrDirs() (target *[]string) {
target = new([]string)
p.ExistingFilesOrDirsVar(target)
return
} | [
"func",
"(",
"p",
"*",
"parserMixin",
")",
"ExistingFilesOrDirs",
"(",
")",
"(",
"target",
"*",
"[",
"]",
"string",
")",
"{",
"target",
"=",
"new",
"(",
"[",
"]",
"string",
")",
"\n",
"p",
".",
"ExistingFilesOrDirsVar",
"(",
"target",
")",
"\n",
"return",
"\n",
"}"
]
| // ExistingFilesOrDirs accumulates string values into a slice. | [
"ExistingFilesOrDirs",
"accumulates",
"string",
"values",
"into",
"a",
"slice",
"."
]
| ef6e7c151c4fdbd3fe78aad001729fee08fa0932 | https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L682-L686 |
148,105 | alecthomas/kingpin | values_generated.go | ResolvedIP | func (p *parserMixin) ResolvedIP() (target *net.IP) {
target = new(net.IP)
p.ResolvedIPVar(target)
return
} | go | func (p *parserMixin) ResolvedIP() (target *net.IP) {
target = new(net.IP)
p.ResolvedIPVar(target)
return
} | [
"func",
"(",
"p",
"*",
"parserMixin",
")",
"ResolvedIP",
"(",
")",
"(",
"target",
"*",
"net",
".",
"IP",
")",
"{",
"target",
"=",
"new",
"(",
"net",
".",
"IP",
")",
"\n",
"p",
".",
"ResolvedIPVar",
"(",
"target",
")",
"\n",
"return",
"\n",
"}"
]
| // Resolve a hostname or IP to an IP. | [
"Resolve",
"a",
"hostname",
"or",
"IP",
"to",
"an",
"IP",
"."
]
| ef6e7c151c4fdbd3fe78aad001729fee08fa0932 | https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L757-L761 |
148,106 | alecthomas/kingpin | values_generated.go | ResolvedIPList | func (p *parserMixin) ResolvedIPList() (target *[]net.IP) {
target = new([]net.IP)
p.ResolvedIPListVar(target)
return
} | go | func (p *parserMixin) ResolvedIPList() (target *[]net.IP) {
target = new([]net.IP)
p.ResolvedIPListVar(target)
return
} | [
"func",
"(",
"p",
"*",
"parserMixin",
")",
"ResolvedIPList",
"(",
")",
"(",
"target",
"*",
"[",
"]",
"net",
".",
"IP",
")",
"{",
"target",
"=",
"new",
"(",
"[",
"]",
"net",
".",
"IP",
")",
"\n",
"p",
".",
"ResolvedIPListVar",
"(",
"target",
")",
"\n",
"return",
"\n",
"}"
]
| // ResolvedIPList accumulates net.IP values into a slice. | [
"ResolvedIPList",
"accumulates",
"net",
".",
"IP",
"values",
"into",
"a",
"slice",
"."
]
| ef6e7c151c4fdbd3fe78aad001729fee08fa0932 | https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L768-L772 |
148,107 | alecthomas/kingpin | values_generated.go | HexBytes | func (p *parserMixin) HexBytes() (target *[]byte) {
target = new([]byte)
p.HexBytesVar(target)
return
} | go | func (p *parserMixin) HexBytes() (target *[]byte) {
target = new([]byte)
p.HexBytesVar(target)
return
} | [
"func",
"(",
"p",
"*",
"parserMixin",
")",
"HexBytes",
"(",
")",
"(",
"target",
"*",
"[",
"]",
"byte",
")",
"{",
"target",
"=",
"new",
"(",
"[",
"]",
"byte",
")",
"\n",
"p",
".",
"HexBytesVar",
"(",
"target",
")",
"\n",
"return",
"\n",
"}"
]
| // Bytes as a hex string. | [
"Bytes",
"as",
"a",
"hex",
"string",
"."
]
| ef6e7c151c4fdbd3fe78aad001729fee08fa0932 | https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L800-L804 |
148,108 | alecthomas/kingpin | global.go | Parse | func Parse() string {
selected := MustParse(CommandLine.Parse(os.Args[1:]))
if selected == "" && CommandLine.cmdGroup.have() {
Usage()
CommandLine.terminate(0)
}
return selected
} | go | func Parse() string {
selected := MustParse(CommandLine.Parse(os.Args[1:]))
if selected == "" && CommandLine.cmdGroup.have() {
Usage()
CommandLine.terminate(0)
}
return selected
} | [
"func",
"Parse",
"(",
")",
"string",
"{",
"selected",
":=",
"MustParse",
"(",
"CommandLine",
".",
"Parse",
"(",
"os",
".",
"Args",
"[",
"1",
":",
"]",
")",
")",
"\n",
"if",
"selected",
"==",
"\"",
"\"",
"&&",
"CommandLine",
".",
"cmdGroup",
".",
"have",
"(",
")",
"{",
"Usage",
"(",
")",
"\n",
"CommandLine",
".",
"terminate",
"(",
"0",
")",
"\n",
"}",
"\n",
"return",
"selected",
"\n",
"}"
]
| // Parse and return the selected command. Will call the termination handler if
// an error is encountered. | [
"Parse",
"and",
"return",
"the",
"selected",
"command",
".",
"Will",
"call",
"the",
"termination",
"handler",
"if",
"an",
"error",
"is",
"encountered",
"."
]
| ef6e7c151c4fdbd3fe78aad001729fee08fa0932 | https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/global.go#L38-L45 |
148,109 | alecthomas/kingpin | global.go | FatalIfError | func FatalIfError(err error, format string, args ...interface{}) {
CommandLine.FatalIfError(err, format, args...)
} | go | func FatalIfError(err error, format string, args ...interface{}) {
CommandLine.FatalIfError(err, format, args...)
} | [
"func",
"FatalIfError",
"(",
"err",
"error",
",",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"CommandLine",
".",
"FatalIfError",
"(",
"err",
",",
"format",
",",
"args",
"...",
")",
"\n",
"}"
]
| // FatalIfError prints an error and exits if err is not nil. The error is printed
// with the given prefix. | [
"FatalIfError",
"prints",
"an",
"error",
"and",
"exits",
"if",
"err",
"is",
"not",
"nil",
".",
"The",
"error",
"is",
"printed",
"with",
"the",
"given",
"prefix",
"."
]
| ef6e7c151c4fdbd3fe78aad001729fee08fa0932 | https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/global.go#L59-L61 |
148,110 | alecthomas/kingpin | global.go | FatalUsageContext | func FatalUsageContext(context *ParseContext, format string, args ...interface{}) {
CommandLine.FatalUsageContext(context, format, args...)
} | go | func FatalUsageContext(context *ParseContext, format string, args ...interface{}) {
CommandLine.FatalUsageContext(context, format, args...)
} | [
"func",
"FatalUsageContext",
"(",
"context",
"*",
"ParseContext",
",",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"CommandLine",
".",
"FatalUsageContext",
"(",
"context",
",",
"format",
",",
"args",
"...",
")",
"\n",
"}"
]
| // FatalUsageContext writes a printf formatted error message to stderr, then
// usage information for the given ParseContext, before exiting. | [
"FatalUsageContext",
"writes",
"a",
"printf",
"formatted",
"error",
"message",
"to",
"stderr",
"then",
"usage",
"information",
"for",
"the",
"given",
"ParseContext",
"before",
"exiting",
"."
]
| ef6e7c151c4fdbd3fe78aad001729fee08fa0932 | https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/global.go#L71-L73 |
148,111 | alecthomas/kingpin | args.go | GetArg | func (a *argGroup) GetArg(name string) *ArgClause {
for _, arg := range a.args {
if arg.name == name {
return arg
}
}
return nil
} | go | func (a *argGroup) GetArg(name string) *ArgClause {
for _, arg := range a.args {
if arg.name == name {
return arg
}
}
return nil
} | [
"func",
"(",
"a",
"*",
"argGroup",
")",
"GetArg",
"(",
"name",
"string",
")",
"*",
"ArgClause",
"{",
"for",
"_",
",",
"arg",
":=",
"range",
"a",
".",
"args",
"{",
"if",
"arg",
".",
"name",
"==",
"name",
"{",
"return",
"arg",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // GetArg gets an argument definition.
//
// This allows existing arguments to be modified after definition but before parsing. Useful for
// modular applications. | [
"GetArg",
"gets",
"an",
"argument",
"definition",
".",
"This",
"allows",
"existing",
"arguments",
"to",
"be",
"modified",
"after",
"definition",
"but",
"before",
"parsing",
".",
"Useful",
"for",
"modular",
"applications",
"."
]
| ef6e7c151c4fdbd3fe78aad001729fee08fa0932 | https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/args.go#L23-L30 |
148,112 | alecthomas/kingpin | completions.go | addHintActionBuiltin | func (a *completionsMixin) addHintActionBuiltin(action HintAction) {
a.builtinHintActions = append(a.builtinHintActions, action)
} | go | func (a *completionsMixin) addHintActionBuiltin(action HintAction) {
a.builtinHintActions = append(a.builtinHintActions, action)
} | [
"func",
"(",
"a",
"*",
"completionsMixin",
")",
"addHintActionBuiltin",
"(",
"action",
"HintAction",
")",
"{",
"a",
".",
"builtinHintActions",
"=",
"append",
"(",
"a",
".",
"builtinHintActions",
",",
"action",
")",
"\n",
"}"
]
| // Allow adding of HintActions which are added internally, ie, EnumVar | [
"Allow",
"adding",
"of",
"HintActions",
"which",
"are",
"added",
"internally",
"ie",
"EnumVar"
]
| ef6e7c151c4fdbd3fe78aad001729fee08fa0932 | https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/completions.go#L16-L18 |
148,113 | alecthomas/kingpin | cmd.go | CmdCompletion | func (c *cmdMixin) CmdCompletion(context *ParseContext) []string {
var options []string
// Count args already satisfied - we won't complete those, and add any
// default commands' alternatives, since they weren't listed explicitly
// and the user may want to explicitly list something else.
argsSatisfied := 0
allSatisfied := false
ElementLoop:
for _, el := range context.Elements {
switch clause := el.Clause.(type) {
case *ArgClause:
// Each new element should reset the previous state
allSatisfied = false
options = nil
if el.Value != nil && *el.Value != "" {
// Get the list of valid options for the last argument
validOptions := c.argGroup.args[argsSatisfied].resolveCompletions()
if len(validOptions) == 0 {
// If there are no options for this argument,
// mark is as allSatisfied as we can't suggest anything
argsSatisfied++
allSatisfied = true
continue ElementLoop
}
for _, opt := range validOptions {
if opt == *el.Value {
// We have an exact match
// We don't need to suggest any option
argsSatisfied++
continue ElementLoop
}
if strings.HasPrefix(opt, *el.Value) {
// If the option match the partially entered argument, add it to the list
options = append(options, opt)
}
}
// Avoid further completion as we have done everything we could
argsSatisfied++
allSatisfied = true
}
case *CmdClause:
options = append(options, clause.completionAlts...)
default:
}
}
if argsSatisfied < len(c.argGroup.args) && !allSatisfied {
// Since not all args have been satisfied, show options for the current one
options = append(options, c.argGroup.args[argsSatisfied].resolveCompletions()...)
} else {
// If all args are satisfied, then go back to completing commands
for _, cmd := range c.cmdGroup.commandOrder {
if !cmd.hidden {
options = append(options, cmd.name)
}
}
}
return options
} | go | func (c *cmdMixin) CmdCompletion(context *ParseContext) []string {
var options []string
// Count args already satisfied - we won't complete those, and add any
// default commands' alternatives, since they weren't listed explicitly
// and the user may want to explicitly list something else.
argsSatisfied := 0
allSatisfied := false
ElementLoop:
for _, el := range context.Elements {
switch clause := el.Clause.(type) {
case *ArgClause:
// Each new element should reset the previous state
allSatisfied = false
options = nil
if el.Value != nil && *el.Value != "" {
// Get the list of valid options for the last argument
validOptions := c.argGroup.args[argsSatisfied].resolveCompletions()
if len(validOptions) == 0 {
// If there are no options for this argument,
// mark is as allSatisfied as we can't suggest anything
argsSatisfied++
allSatisfied = true
continue ElementLoop
}
for _, opt := range validOptions {
if opt == *el.Value {
// We have an exact match
// We don't need to suggest any option
argsSatisfied++
continue ElementLoop
}
if strings.HasPrefix(opt, *el.Value) {
// If the option match the partially entered argument, add it to the list
options = append(options, opt)
}
}
// Avoid further completion as we have done everything we could
argsSatisfied++
allSatisfied = true
}
case *CmdClause:
options = append(options, clause.completionAlts...)
default:
}
}
if argsSatisfied < len(c.argGroup.args) && !allSatisfied {
// Since not all args have been satisfied, show options for the current one
options = append(options, c.argGroup.args[argsSatisfied].resolveCompletions()...)
} else {
// If all args are satisfied, then go back to completing commands
for _, cmd := range c.cmdGroup.commandOrder {
if !cmd.hidden {
options = append(options, cmd.name)
}
}
}
return options
} | [
"func",
"(",
"c",
"*",
"cmdMixin",
")",
"CmdCompletion",
"(",
"context",
"*",
"ParseContext",
")",
"[",
"]",
"string",
"{",
"var",
"options",
"[",
"]",
"string",
"\n\n",
"// Count args already satisfied - we won't complete those, and add any",
"// default commands' alternatives, since they weren't listed explicitly",
"// and the user may want to explicitly list something else.",
"argsSatisfied",
":=",
"0",
"\n",
"allSatisfied",
":=",
"false",
"\n",
"ElementLoop",
":",
"for",
"_",
",",
"el",
":=",
"range",
"context",
".",
"Elements",
"{",
"switch",
"clause",
":=",
"el",
".",
"Clause",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ArgClause",
":",
"// Each new element should reset the previous state",
"allSatisfied",
"=",
"false",
"\n",
"options",
"=",
"nil",
"\n\n",
"if",
"el",
".",
"Value",
"!=",
"nil",
"&&",
"*",
"el",
".",
"Value",
"!=",
"\"",
"\"",
"{",
"// Get the list of valid options for the last argument",
"validOptions",
":=",
"c",
".",
"argGroup",
".",
"args",
"[",
"argsSatisfied",
"]",
".",
"resolveCompletions",
"(",
")",
"\n",
"if",
"len",
"(",
"validOptions",
")",
"==",
"0",
"{",
"// If there are no options for this argument,",
"// mark is as allSatisfied as we can't suggest anything",
"argsSatisfied",
"++",
"\n",
"allSatisfied",
"=",
"true",
"\n",
"continue",
"ElementLoop",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"opt",
":=",
"range",
"validOptions",
"{",
"if",
"opt",
"==",
"*",
"el",
".",
"Value",
"{",
"// We have an exact match",
"// We don't need to suggest any option",
"argsSatisfied",
"++",
"\n",
"continue",
"ElementLoop",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"opt",
",",
"*",
"el",
".",
"Value",
")",
"{",
"// If the option match the partially entered argument, add it to the list",
"options",
"=",
"append",
"(",
"options",
",",
"opt",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// Avoid further completion as we have done everything we could",
"argsSatisfied",
"++",
"\n",
"allSatisfied",
"=",
"true",
"\n",
"}",
"\n",
"case",
"*",
"CmdClause",
":",
"options",
"=",
"append",
"(",
"options",
",",
"clause",
".",
"completionAlts",
"...",
")",
"\n",
"default",
":",
"}",
"\n",
"}",
"\n\n",
"if",
"argsSatisfied",
"<",
"len",
"(",
"c",
".",
"argGroup",
".",
"args",
")",
"&&",
"!",
"allSatisfied",
"{",
"// Since not all args have been satisfied, show options for the current one",
"options",
"=",
"append",
"(",
"options",
",",
"c",
".",
"argGroup",
".",
"args",
"[",
"argsSatisfied",
"]",
".",
"resolveCompletions",
"(",
")",
"...",
")",
"\n",
"}",
"else",
"{",
"// If all args are satisfied, then go back to completing commands",
"for",
"_",
",",
"cmd",
":=",
"range",
"c",
".",
"cmdGroup",
".",
"commandOrder",
"{",
"if",
"!",
"cmd",
".",
"hidden",
"{",
"options",
"=",
"append",
"(",
"options",
",",
"cmd",
".",
"name",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"options",
"\n",
"}"
]
| // CmdCompletion returns completion options for arguments, if that's where
// parsing left off, or commands if there aren't any unsatisfied args. | [
"CmdCompletion",
"returns",
"completion",
"options",
"for",
"arguments",
"if",
"that",
"s",
"where",
"parsing",
"left",
"off",
"or",
"commands",
"if",
"there",
"aren",
"t",
"any",
"unsatisfied",
"args",
"."
]
| ef6e7c151c4fdbd3fe78aad001729fee08fa0932 | https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/cmd.go#L17-L79 |
148,114 | alecthomas/kingpin | cmd.go | Alias | func (c *CmdClause) Alias(name string) *CmdClause {
c.aliases = append(c.aliases, name)
return c
} | go | func (c *CmdClause) Alias(name string) *CmdClause {
c.aliases = append(c.aliases, name)
return c
} | [
"func",
"(",
"c",
"*",
"CmdClause",
")",
"Alias",
"(",
"name",
"string",
")",
"*",
"CmdClause",
"{",
"c",
".",
"aliases",
"=",
"append",
"(",
"c",
".",
"aliases",
",",
"name",
")",
"\n",
"return",
"c",
"\n",
"}"
]
| // Add an Alias for this command. | [
"Add",
"an",
"Alias",
"for",
"this",
"command",
"."
]
| ef6e7c151c4fdbd3fe78aad001729fee08fa0932 | https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/cmd.go#L243-L246 |
148,115 | alecthomas/kingpin | cmd.go | Command | func (c *CmdClause) Command(name, help string) *CmdClause {
cmd := c.addCommand(name, help)
cmd.parent = c
return cmd
} | go | func (c *CmdClause) Command(name, help string) *CmdClause {
cmd := c.addCommand(name, help)
cmd.parent = c
return cmd
} | [
"func",
"(",
"c",
"*",
"CmdClause",
")",
"Command",
"(",
"name",
",",
"help",
"string",
")",
"*",
"CmdClause",
"{",
"cmd",
":=",
"c",
".",
"addCommand",
"(",
"name",
",",
"help",
")",
"\n",
"cmd",
".",
"parent",
"=",
"c",
"\n",
"return",
"cmd",
"\n",
"}"
]
| // Command adds a new sub-command. | [
"Command",
"adds",
"a",
"new",
"sub",
"-",
"command",
"."
]
| ef6e7c151c4fdbd3fe78aad001729fee08fa0932 | https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/cmd.go#L263-L267 |
148,116 | alecthomas/kingpin | parser.go | Next | func (p *ParseContext) Next() *Token {
if len(p.peek) > 0 {
return p.pop()
}
// End of tokens.
if len(p.args) == 0 {
return &Token{Index: p.argi, Type: TokenEOL}
}
arg := p.args[0]
p.next()
if p.argsOnly {
return &Token{p.argi, TokenArg, arg}
}
// All remaining args are passed directly.
if arg == "--" {
p.argsOnly = true
return p.Next()
}
if strings.HasPrefix(arg, "--") {
parts := strings.SplitN(arg[2:], "=", 2)
token := &Token{p.argi, TokenLong, parts[0]}
if len(parts) == 2 {
p.Push(&Token{p.argi, TokenArg, parts[1]})
}
return token
}
if strings.HasPrefix(arg, "-") {
if len(arg) == 1 {
return &Token{Index: p.argi, Type: TokenShort}
}
shortRune, size := utf8.DecodeRuneInString(arg[1:])
short := string(shortRune)
flag, ok := p.flags.short[short]
// Not a known short flag, we'll just return it anyway.
if !ok {
} else if fb, ok := flag.value.(boolFlag); ok && fb.IsBoolFlag() {
// Bool short flag.
} else {
// Short flag with combined argument: -fARG
token := &Token{p.argi, TokenShort, short}
if len(arg) > size+1 {
p.Push(&Token{p.argi, TokenArg, arg[size+1:]})
}
return token
}
if len(arg) > size+1 {
p.args = append([]string{"-" + arg[size+1:]}, p.args...)
}
return &Token{p.argi, TokenShort, short}
} else if EnableFileExpansion && strings.HasPrefix(arg, "@") {
expanded, err := ExpandArgsFromFile(arg[1:])
if err != nil {
return &Token{p.argi, TokenError, err.Error()}
}
if len(p.args) == 0 {
p.args = expanded
} else {
p.args = append(expanded, p.args...)
}
return p.Next()
}
return &Token{p.argi, TokenArg, arg}
} | go | func (p *ParseContext) Next() *Token {
if len(p.peek) > 0 {
return p.pop()
}
// End of tokens.
if len(p.args) == 0 {
return &Token{Index: p.argi, Type: TokenEOL}
}
arg := p.args[0]
p.next()
if p.argsOnly {
return &Token{p.argi, TokenArg, arg}
}
// All remaining args are passed directly.
if arg == "--" {
p.argsOnly = true
return p.Next()
}
if strings.HasPrefix(arg, "--") {
parts := strings.SplitN(arg[2:], "=", 2)
token := &Token{p.argi, TokenLong, parts[0]}
if len(parts) == 2 {
p.Push(&Token{p.argi, TokenArg, parts[1]})
}
return token
}
if strings.HasPrefix(arg, "-") {
if len(arg) == 1 {
return &Token{Index: p.argi, Type: TokenShort}
}
shortRune, size := utf8.DecodeRuneInString(arg[1:])
short := string(shortRune)
flag, ok := p.flags.short[short]
// Not a known short flag, we'll just return it anyway.
if !ok {
} else if fb, ok := flag.value.(boolFlag); ok && fb.IsBoolFlag() {
// Bool short flag.
} else {
// Short flag with combined argument: -fARG
token := &Token{p.argi, TokenShort, short}
if len(arg) > size+1 {
p.Push(&Token{p.argi, TokenArg, arg[size+1:]})
}
return token
}
if len(arg) > size+1 {
p.args = append([]string{"-" + arg[size+1:]}, p.args...)
}
return &Token{p.argi, TokenShort, short}
} else if EnableFileExpansion && strings.HasPrefix(arg, "@") {
expanded, err := ExpandArgsFromFile(arg[1:])
if err != nil {
return &Token{p.argi, TokenError, err.Error()}
}
if len(p.args) == 0 {
p.args = expanded
} else {
p.args = append(expanded, p.args...)
}
return p.Next()
}
return &Token{p.argi, TokenArg, arg}
} | [
"func",
"(",
"p",
"*",
"ParseContext",
")",
"Next",
"(",
")",
"*",
"Token",
"{",
"if",
"len",
"(",
"p",
".",
"peek",
")",
">",
"0",
"{",
"return",
"p",
".",
"pop",
"(",
")",
"\n",
"}",
"\n\n",
"// End of tokens.",
"if",
"len",
"(",
"p",
".",
"args",
")",
"==",
"0",
"{",
"return",
"&",
"Token",
"{",
"Index",
":",
"p",
".",
"argi",
",",
"Type",
":",
"TokenEOL",
"}",
"\n",
"}",
"\n\n",
"arg",
":=",
"p",
".",
"args",
"[",
"0",
"]",
"\n",
"p",
".",
"next",
"(",
")",
"\n\n",
"if",
"p",
".",
"argsOnly",
"{",
"return",
"&",
"Token",
"{",
"p",
".",
"argi",
",",
"TokenArg",
",",
"arg",
"}",
"\n",
"}",
"\n\n",
"// All remaining args are passed directly.",
"if",
"arg",
"==",
"\"",
"\"",
"{",
"p",
".",
"argsOnly",
"=",
"true",
"\n",
"return",
"p",
".",
"Next",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"arg",
",",
"\"",
"\"",
")",
"{",
"parts",
":=",
"strings",
".",
"SplitN",
"(",
"arg",
"[",
"2",
":",
"]",
",",
"\"",
"\"",
",",
"2",
")",
"\n",
"token",
":=",
"&",
"Token",
"{",
"p",
".",
"argi",
",",
"TokenLong",
",",
"parts",
"[",
"0",
"]",
"}",
"\n",
"if",
"len",
"(",
"parts",
")",
"==",
"2",
"{",
"p",
".",
"Push",
"(",
"&",
"Token",
"{",
"p",
".",
"argi",
",",
"TokenArg",
",",
"parts",
"[",
"1",
"]",
"}",
")",
"\n",
"}",
"\n",
"return",
"token",
"\n",
"}",
"\n\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"arg",
",",
"\"",
"\"",
")",
"{",
"if",
"len",
"(",
"arg",
")",
"==",
"1",
"{",
"return",
"&",
"Token",
"{",
"Index",
":",
"p",
".",
"argi",
",",
"Type",
":",
"TokenShort",
"}",
"\n",
"}",
"\n",
"shortRune",
",",
"size",
":=",
"utf8",
".",
"DecodeRuneInString",
"(",
"arg",
"[",
"1",
":",
"]",
")",
"\n",
"short",
":=",
"string",
"(",
"shortRune",
")",
"\n",
"flag",
",",
"ok",
":=",
"p",
".",
"flags",
".",
"short",
"[",
"short",
"]",
"\n",
"// Not a known short flag, we'll just return it anyway.",
"if",
"!",
"ok",
"{",
"}",
"else",
"if",
"fb",
",",
"ok",
":=",
"flag",
".",
"value",
".",
"(",
"boolFlag",
")",
";",
"ok",
"&&",
"fb",
".",
"IsBoolFlag",
"(",
")",
"{",
"// Bool short flag.",
"}",
"else",
"{",
"// Short flag with combined argument: -fARG",
"token",
":=",
"&",
"Token",
"{",
"p",
".",
"argi",
",",
"TokenShort",
",",
"short",
"}",
"\n",
"if",
"len",
"(",
"arg",
")",
">",
"size",
"+",
"1",
"{",
"p",
".",
"Push",
"(",
"&",
"Token",
"{",
"p",
".",
"argi",
",",
"TokenArg",
",",
"arg",
"[",
"size",
"+",
"1",
":",
"]",
"}",
")",
"\n",
"}",
"\n",
"return",
"token",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"arg",
")",
">",
"size",
"+",
"1",
"{",
"p",
".",
"args",
"=",
"append",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
"+",
"arg",
"[",
"size",
"+",
"1",
":",
"]",
"}",
",",
"p",
".",
"args",
"...",
")",
"\n",
"}",
"\n",
"return",
"&",
"Token",
"{",
"p",
".",
"argi",
",",
"TokenShort",
",",
"short",
"}",
"\n",
"}",
"else",
"if",
"EnableFileExpansion",
"&&",
"strings",
".",
"HasPrefix",
"(",
"arg",
",",
"\"",
"\"",
")",
"{",
"expanded",
",",
"err",
":=",
"ExpandArgsFromFile",
"(",
"arg",
"[",
"1",
":",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"&",
"Token",
"{",
"p",
".",
"argi",
",",
"TokenError",
",",
"err",
".",
"Error",
"(",
")",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"p",
".",
"args",
")",
"==",
"0",
"{",
"p",
".",
"args",
"=",
"expanded",
"\n",
"}",
"else",
"{",
"p",
".",
"args",
"=",
"append",
"(",
"expanded",
",",
"p",
".",
"args",
"...",
")",
"\n",
"}",
"\n",
"return",
"p",
".",
"Next",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"Token",
"{",
"p",
".",
"argi",
",",
"TokenArg",
",",
"arg",
"}",
"\n",
"}"
]
| // Next token in the parse context. | [
"Next",
"token",
"in",
"the",
"parse",
"context",
"."
]
| ef6e7c151c4fdbd3fe78aad001729fee08fa0932 | https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/parser.go#L161-L231 |
148,117 | alecthomas/kingpin | usage.go | Usage | func (a *Application) Usage(args []string) {
context, err := a.parseContext(true, args)
a.FatalIfError(err, "")
if err := a.UsageForContextWithTemplate(context, 2, a.usageTemplate); err != nil {
panic(err)
}
} | go | func (a *Application) Usage(args []string) {
context, err := a.parseContext(true, args)
a.FatalIfError(err, "")
if err := a.UsageForContextWithTemplate(context, 2, a.usageTemplate); err != nil {
panic(err)
}
} | [
"func",
"(",
"a",
"*",
"Application",
")",
"Usage",
"(",
"args",
"[",
"]",
"string",
")",
"{",
"context",
",",
"err",
":=",
"a",
".",
"parseContext",
"(",
"true",
",",
"args",
")",
"\n",
"a",
".",
"FatalIfError",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
":=",
"a",
".",
"UsageForContextWithTemplate",
"(",
"context",
",",
"2",
",",
"a",
".",
"usageTemplate",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
]
| // Usage writes application usage to w. It parses args to determine
// appropriate help context, such as which command to show help for. | [
"Usage",
"writes",
"application",
"usage",
"to",
"w",
".",
"It",
"parses",
"args",
"to",
"determine",
"appropriate",
"help",
"context",
"such",
"as",
"which",
"command",
"to",
"show",
"help",
"for",
"."
]
| ef6e7c151c4fdbd3fe78aad001729fee08fa0932 | https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/usage.go#L46-L52 |
148,118 | emersion/go-imap | search.go | ParseWithCharset | func (c *SearchCriteria) ParseWithCharset(fields []interface{}, charsetReader func(io.Reader) io.Reader) error {
for len(fields) > 0 {
var err error
if fields, err = c.parseField(fields, charsetReader); err != nil {
return err
}
}
return nil
} | go | func (c *SearchCriteria) ParseWithCharset(fields []interface{}, charsetReader func(io.Reader) io.Reader) error {
for len(fields) > 0 {
var err error
if fields, err = c.parseField(fields, charsetReader); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"c",
"*",
"SearchCriteria",
")",
"ParseWithCharset",
"(",
"fields",
"[",
"]",
"interface",
"{",
"}",
",",
"charsetReader",
"func",
"(",
"io",
".",
"Reader",
")",
"io",
".",
"Reader",
")",
"error",
"{",
"for",
"len",
"(",
"fields",
")",
">",
"0",
"{",
"var",
"err",
"error",
"\n",
"if",
"fields",
",",
"err",
"=",
"c",
".",
"parseField",
"(",
"fields",
",",
"charsetReader",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // ParseWithCharset parses a search criteria from the provided fields.
// charsetReader is an optional function that converts from the fields charset
// to UTF-8. | [
"ParseWithCharset",
"parses",
"a",
"search",
"criteria",
"from",
"the",
"provided",
"fields",
".",
"charsetReader",
"is",
"an",
"optional",
"function",
"that",
"converts",
"from",
"the",
"fields",
"charset",
"to",
"UTF",
"-",
"8",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/search.go#L264-L272 |
148,119 | emersion/go-imap | backend/backendutil/envelope.go | FetchEnvelope | func FetchEnvelope(h message.Header) (*imap.Envelope, error) {
mh := mail.Header{Header: h}
env := new(imap.Envelope)
env.Date, _ = mh.Date()
env.Subject, _ = mh.Subject()
env.From, _ = headerAddressList(mh, "From")
env.Sender, _ = headerAddressList(mh, "Sender")
env.ReplyTo, _ = headerAddressList(mh, "Reply-To")
env.To, _ = headerAddressList(mh, "To")
env.Cc, _ = headerAddressList(mh, "Cc")
env.Bcc, _ = headerAddressList(mh, "Bcc")
env.InReplyTo = mh.Get("In-Reply-To")
env.MessageId = mh.Get("Message-Id")
return env, nil
} | go | func FetchEnvelope(h message.Header) (*imap.Envelope, error) {
mh := mail.Header{Header: h}
env := new(imap.Envelope)
env.Date, _ = mh.Date()
env.Subject, _ = mh.Subject()
env.From, _ = headerAddressList(mh, "From")
env.Sender, _ = headerAddressList(mh, "Sender")
env.ReplyTo, _ = headerAddressList(mh, "Reply-To")
env.To, _ = headerAddressList(mh, "To")
env.Cc, _ = headerAddressList(mh, "Cc")
env.Bcc, _ = headerAddressList(mh, "Bcc")
env.InReplyTo = mh.Get("In-Reply-To")
env.MessageId = mh.Get("Message-Id")
return env, nil
} | [
"func",
"FetchEnvelope",
"(",
"h",
"message",
".",
"Header",
")",
"(",
"*",
"imap",
".",
"Envelope",
",",
"error",
")",
"{",
"mh",
":=",
"mail",
".",
"Header",
"{",
"Header",
":",
"h",
"}",
"\n\n",
"env",
":=",
"new",
"(",
"imap",
".",
"Envelope",
")",
"\n",
"env",
".",
"Date",
",",
"_",
"=",
"mh",
".",
"Date",
"(",
")",
"\n",
"env",
".",
"Subject",
",",
"_",
"=",
"mh",
".",
"Subject",
"(",
")",
"\n",
"env",
".",
"From",
",",
"_",
"=",
"headerAddressList",
"(",
"mh",
",",
"\"",
"\"",
")",
"\n",
"env",
".",
"Sender",
",",
"_",
"=",
"headerAddressList",
"(",
"mh",
",",
"\"",
"\"",
")",
"\n",
"env",
".",
"ReplyTo",
",",
"_",
"=",
"headerAddressList",
"(",
"mh",
",",
"\"",
"\"",
")",
"\n",
"env",
".",
"To",
",",
"_",
"=",
"headerAddressList",
"(",
"mh",
",",
"\"",
"\"",
")",
"\n",
"env",
".",
"Cc",
",",
"_",
"=",
"headerAddressList",
"(",
"mh",
",",
"\"",
"\"",
")",
"\n",
"env",
".",
"Bcc",
",",
"_",
"=",
"headerAddressList",
"(",
"mh",
",",
"\"",
"\"",
")",
"\n",
"env",
".",
"InReplyTo",
"=",
"mh",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"env",
".",
"MessageId",
"=",
"mh",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n\n",
"return",
"env",
",",
"nil",
"\n",
"}"
]
| // FetchEnvelope returns a message's envelope from its header. | [
"FetchEnvelope",
"returns",
"a",
"message",
"s",
"envelope",
"from",
"its",
"header",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/backend/backendutil/envelope.go#L34-L50 |
148,120 | emersion/go-imap | backend/backendutil/flags.go | UpdateFlags | func UpdateFlags(current []string, op imap.FlagsOp, flags []string) []string {
switch op {
case imap.SetFlags:
// TODO: keep \Recent if it is present
return flags
case imap.AddFlags:
// Check for duplicates
for _, flag := range current {
for i, addFlag := range flags {
if addFlag == flag {
flags = append(flags[:i], flags[i+1:]...)
break
}
}
}
return append(current, flags...)
case imap.RemoveFlags:
// Iterate through flags from the last one to the first one, to be able to
// delete some of them.
for i := len(current) - 1; i >= 0; i-- {
flag := current[i]
for _, removeFlag := range flags {
if removeFlag == flag {
current = append(current[:i], current[i+1:]...)
break
}
}
}
return current
}
return current
} | go | func UpdateFlags(current []string, op imap.FlagsOp, flags []string) []string {
switch op {
case imap.SetFlags:
// TODO: keep \Recent if it is present
return flags
case imap.AddFlags:
// Check for duplicates
for _, flag := range current {
for i, addFlag := range flags {
if addFlag == flag {
flags = append(flags[:i], flags[i+1:]...)
break
}
}
}
return append(current, flags...)
case imap.RemoveFlags:
// Iterate through flags from the last one to the first one, to be able to
// delete some of them.
for i := len(current) - 1; i >= 0; i-- {
flag := current[i]
for _, removeFlag := range flags {
if removeFlag == flag {
current = append(current[:i], current[i+1:]...)
break
}
}
}
return current
}
return current
} | [
"func",
"UpdateFlags",
"(",
"current",
"[",
"]",
"string",
",",
"op",
"imap",
".",
"FlagsOp",
",",
"flags",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"switch",
"op",
"{",
"case",
"imap",
".",
"SetFlags",
":",
"// TODO: keep \\Recent if it is present",
"return",
"flags",
"\n",
"case",
"imap",
".",
"AddFlags",
":",
"// Check for duplicates",
"for",
"_",
",",
"flag",
":=",
"range",
"current",
"{",
"for",
"i",
",",
"addFlag",
":=",
"range",
"flags",
"{",
"if",
"addFlag",
"==",
"flag",
"{",
"flags",
"=",
"append",
"(",
"flags",
"[",
":",
"i",
"]",
",",
"flags",
"[",
"i",
"+",
"1",
":",
"]",
"...",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"append",
"(",
"current",
",",
"flags",
"...",
")",
"\n",
"case",
"imap",
".",
"RemoveFlags",
":",
"// Iterate through flags from the last one to the first one, to be able to",
"// delete some of them.",
"for",
"i",
":=",
"len",
"(",
"current",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"flag",
":=",
"current",
"[",
"i",
"]",
"\n\n",
"for",
"_",
",",
"removeFlag",
":=",
"range",
"flags",
"{",
"if",
"removeFlag",
"==",
"flag",
"{",
"current",
"=",
"append",
"(",
"current",
"[",
":",
"i",
"]",
",",
"current",
"[",
"i",
"+",
"1",
":",
"]",
"...",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"current",
"\n",
"}",
"\n",
"return",
"current",
"\n",
"}"
]
| // UpdateFlags executes a flag operation on the flag set current. | [
"UpdateFlags",
"executes",
"a",
"flag",
"operation",
"on",
"the",
"flag",
"set",
"current",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/backend/backendutil/flags.go#L8-L40 |
148,121 | emersion/go-imap | mailbox.go | CanonicalMailboxName | func CanonicalMailboxName(name string) string {
if strings.ToUpper(name) == InboxName {
return InboxName
}
return name
} | go | func CanonicalMailboxName(name string) string {
if strings.ToUpper(name) == InboxName {
return InboxName
}
return name
} | [
"func",
"CanonicalMailboxName",
"(",
"name",
"string",
")",
"string",
"{",
"if",
"strings",
".",
"ToUpper",
"(",
"name",
")",
"==",
"InboxName",
"{",
"return",
"InboxName",
"\n",
"}",
"\n",
"return",
"name",
"\n",
"}"
]
| // CanonicalMailboxName returns the canonical form of a mailbox name. Mailbox names can be
// case-sensitive or case-insensitive depending on the backend implementation.
// The special INBOX mailbox is case-insensitive. | [
"CanonicalMailboxName",
"returns",
"the",
"canonical",
"form",
"of",
"a",
"mailbox",
"name",
".",
"Mailbox",
"names",
"can",
"be",
"case",
"-",
"sensitive",
"or",
"case",
"-",
"insensitive",
"depending",
"on",
"the",
"backend",
"implementation",
".",
"The",
"special",
"INBOX",
"mailbox",
"is",
"case",
"-",
"insensitive",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/mailbox.go#L18-L23 |
148,122 | emersion/go-imap | mailbox.go | Parse | func (info *MailboxInfo) Parse(fields []interface{}) error {
if len(fields) < 3 {
return errors.New("Mailbox info needs at least 3 fields")
}
var err error
if info.Attributes, err = ParseStringList(fields[0]); err != nil {
return err
}
var ok bool
if info.Delimiter, ok = fields[1].(string); !ok {
return errors.New("Mailbox delimiter must be a string")
}
if name, err := ParseString(fields[2]); err != nil {
return err
} else if name, err := utf7.Encoding.NewDecoder().String(name); err != nil {
return err
} else {
info.Name = CanonicalMailboxName(name)
}
return nil
} | go | func (info *MailboxInfo) Parse(fields []interface{}) error {
if len(fields) < 3 {
return errors.New("Mailbox info needs at least 3 fields")
}
var err error
if info.Attributes, err = ParseStringList(fields[0]); err != nil {
return err
}
var ok bool
if info.Delimiter, ok = fields[1].(string); !ok {
return errors.New("Mailbox delimiter must be a string")
}
if name, err := ParseString(fields[2]); err != nil {
return err
} else if name, err := utf7.Encoding.NewDecoder().String(name); err != nil {
return err
} else {
info.Name = CanonicalMailboxName(name)
}
return nil
} | [
"func",
"(",
"info",
"*",
"MailboxInfo",
")",
"Parse",
"(",
"fields",
"[",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"len",
"(",
"fields",
")",
"<",
"3",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"err",
"error",
"\n",
"if",
"info",
".",
"Attributes",
",",
"err",
"=",
"ParseStringList",
"(",
"fields",
"[",
"0",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"var",
"ok",
"bool",
"\n",
"if",
"info",
".",
"Delimiter",
",",
"ok",
"=",
"fields",
"[",
"1",
"]",
".",
"(",
"string",
")",
";",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"name",
",",
"err",
":=",
"ParseString",
"(",
"fields",
"[",
"2",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"else",
"if",
"name",
",",
"err",
":=",
"utf7",
".",
"Encoding",
".",
"NewDecoder",
"(",
")",
".",
"String",
"(",
"name",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"else",
"{",
"info",
".",
"Name",
"=",
"CanonicalMailboxName",
"(",
"name",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // Parse mailbox info from fields. | [
"Parse",
"mailbox",
"info",
"from",
"fields",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/mailbox.go#L52-L76 |
148,123 | emersion/go-imap | mailbox.go | Format | func (info *MailboxInfo) Format() []interface{} {
name, _ := utf7.Encoding.NewEncoder().String(info.Name)
attrs := make([]interface{}, len(info.Attributes))
for i, attr := range info.Attributes {
attrs[i] = Atom(attr)
}
// Thunderbird doesn't understand delimiters if not quoted
return []interface{}{attrs, Quoted(info.Delimiter), name}
} | go | func (info *MailboxInfo) Format() []interface{} {
name, _ := utf7.Encoding.NewEncoder().String(info.Name)
attrs := make([]interface{}, len(info.Attributes))
for i, attr := range info.Attributes {
attrs[i] = Atom(attr)
}
// Thunderbird doesn't understand delimiters if not quoted
return []interface{}{attrs, Quoted(info.Delimiter), name}
} | [
"func",
"(",
"info",
"*",
"MailboxInfo",
")",
"Format",
"(",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"name",
",",
"_",
":=",
"utf7",
".",
"Encoding",
".",
"NewEncoder",
"(",
")",
".",
"String",
"(",
"info",
".",
"Name",
")",
"\n",
"attrs",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"info",
".",
"Attributes",
")",
")",
"\n",
"for",
"i",
",",
"attr",
":=",
"range",
"info",
".",
"Attributes",
"{",
"attrs",
"[",
"i",
"]",
"=",
"Atom",
"(",
"attr",
")",
"\n",
"}",
"\n",
"// Thunderbird doesn't understand delimiters if not quoted",
"return",
"[",
"]",
"interface",
"{",
"}",
"{",
"attrs",
",",
"Quoted",
"(",
"info",
".",
"Delimiter",
")",
",",
"name",
"}",
"\n",
"}"
]
| // Format mailbox info to fields. | [
"Format",
"mailbox",
"info",
"to",
"fields",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/mailbox.go#L79-L87 |
148,124 | emersion/go-imap | mailbox.go | Match | func (info *MailboxInfo) Match(reference, pattern string) bool {
name := info.Name
if strings.HasPrefix(pattern, info.Delimiter) {
reference = ""
pattern = strings.TrimPrefix(pattern, info.Delimiter)
}
if reference != "" {
if !strings.HasSuffix(reference, info.Delimiter) {
reference += info.Delimiter
}
if !strings.HasPrefix(name, reference) {
return false
}
name = strings.TrimPrefix(name, reference)
}
return info.match(name, pattern)
} | go | func (info *MailboxInfo) Match(reference, pattern string) bool {
name := info.Name
if strings.HasPrefix(pattern, info.Delimiter) {
reference = ""
pattern = strings.TrimPrefix(pattern, info.Delimiter)
}
if reference != "" {
if !strings.HasSuffix(reference, info.Delimiter) {
reference += info.Delimiter
}
if !strings.HasPrefix(name, reference) {
return false
}
name = strings.TrimPrefix(name, reference)
}
return info.match(name, pattern)
} | [
"func",
"(",
"info",
"*",
"MailboxInfo",
")",
"Match",
"(",
"reference",
",",
"pattern",
"string",
")",
"bool",
"{",
"name",
":=",
"info",
".",
"Name",
"\n\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"pattern",
",",
"info",
".",
"Delimiter",
")",
"{",
"reference",
"=",
"\"",
"\"",
"\n",
"pattern",
"=",
"strings",
".",
"TrimPrefix",
"(",
"pattern",
",",
"info",
".",
"Delimiter",
")",
"\n",
"}",
"\n",
"if",
"reference",
"!=",
"\"",
"\"",
"{",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"reference",
",",
"info",
".",
"Delimiter",
")",
"{",
"reference",
"+=",
"info",
".",
"Delimiter",
"\n",
"}",
"\n",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"name",
",",
"reference",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"name",
"=",
"strings",
".",
"TrimPrefix",
"(",
"name",
",",
"reference",
")",
"\n",
"}",
"\n\n",
"return",
"info",
".",
"match",
"(",
"name",
",",
"pattern",
")",
"\n",
"}"
]
| // Match checks if a reference and a pattern matches this mailbox name, as
// defined in RFC 3501 section 6.3.8. | [
"Match",
"checks",
"if",
"a",
"reference",
"and",
"a",
"pattern",
"matches",
"this",
"mailbox",
"name",
"as",
"defined",
"in",
"RFC",
"3501",
"section",
"6",
".",
"3",
".",
"8",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/mailbox.go#L123-L141 |
148,125 | emersion/go-imap | mailbox.go | NewMailboxStatus | func NewMailboxStatus(name string, items []StatusItem) *MailboxStatus {
status := &MailboxStatus{
Name: name,
Items: make(map[StatusItem]interface{}),
}
for _, k := range items {
status.Items[k] = nil
}
return status
} | go | func NewMailboxStatus(name string, items []StatusItem) *MailboxStatus {
status := &MailboxStatus{
Name: name,
Items: make(map[StatusItem]interface{}),
}
for _, k := range items {
status.Items[k] = nil
}
return status
} | [
"func",
"NewMailboxStatus",
"(",
"name",
"string",
",",
"items",
"[",
"]",
"StatusItem",
")",
"*",
"MailboxStatus",
"{",
"status",
":=",
"&",
"MailboxStatus",
"{",
"Name",
":",
"name",
",",
"Items",
":",
"make",
"(",
"map",
"[",
"StatusItem",
"]",
"interface",
"{",
"}",
")",
",",
"}",
"\n\n",
"for",
"_",
",",
"k",
":=",
"range",
"items",
"{",
"status",
".",
"Items",
"[",
"k",
"]",
"=",
"nil",
"\n",
"}",
"\n\n",
"return",
"status",
"\n",
"}"
]
| // Create a new mailbox status that will contain the specified items. | [
"Create",
"a",
"new",
"mailbox",
"status",
"that",
"will",
"contain",
"the",
"specified",
"items",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/mailbox.go#L179-L190 |
148,126 | emersion/go-imap | backend/updates.go | NewUpdate | func NewUpdate(username, mailbox string) Update {
return &update{
username: username,
mailbox: mailbox,
}
} | go | func NewUpdate(username, mailbox string) Update {
return &update{
username: username,
mailbox: mailbox,
}
} | [
"func",
"NewUpdate",
"(",
"username",
",",
"mailbox",
"string",
")",
"Update",
"{",
"return",
"&",
"update",
"{",
"username",
":",
"username",
",",
"mailbox",
":",
"mailbox",
",",
"}",
"\n",
"}"
]
| // NewUpdate creates a new update. | [
"NewUpdate",
"creates",
"a",
"new",
"update",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/backend/updates.go#L22-L27 |
148,127 | emersion/go-imap | client/client.go | State | func (c *Client) State() imap.ConnState {
c.locker.Lock()
state := c.state
c.locker.Unlock()
return state
} | go | func (c *Client) State() imap.ConnState {
c.locker.Lock()
state := c.state
c.locker.Unlock()
return state
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"State",
"(",
")",
"imap",
".",
"ConnState",
"{",
"c",
".",
"locker",
".",
"Lock",
"(",
")",
"\n",
"state",
":=",
"c",
".",
"state",
"\n",
"c",
".",
"locker",
".",
"Unlock",
"(",
")",
"\n",
"return",
"state",
"\n",
"}"
]
| // State returns the current connection state. | [
"State",
"returns",
"the",
"current",
"connection",
"state",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/client.go#L278-L283 |
148,128 | emersion/go-imap | client/client.go | Mailbox | func (c *Client) Mailbox() *imap.MailboxStatus {
// c.Mailbox fields are not supposed to change, so we can return the pointer.
c.locker.Lock()
mbox := c.mailbox
c.locker.Unlock()
return mbox
} | go | func (c *Client) Mailbox() *imap.MailboxStatus {
// c.Mailbox fields are not supposed to change, so we can return the pointer.
c.locker.Lock()
mbox := c.mailbox
c.locker.Unlock()
return mbox
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Mailbox",
"(",
")",
"*",
"imap",
".",
"MailboxStatus",
"{",
"// c.Mailbox fields are not supposed to change, so we can return the pointer.",
"c",
".",
"locker",
".",
"Lock",
"(",
")",
"\n",
"mbox",
":=",
"c",
".",
"mailbox",
"\n",
"c",
".",
"locker",
".",
"Unlock",
"(",
")",
"\n",
"return",
"mbox",
"\n",
"}"
]
| // Mailbox returns the selected mailbox. It returns nil if there isn't one. | [
"Mailbox",
"returns",
"the",
"selected",
"mailbox",
".",
"It",
"returns",
"nil",
"if",
"there",
"isn",
"t",
"one",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/client.go#L286-L292 |
148,129 | emersion/go-imap | client/client.go | SetState | func (c *Client) SetState(state imap.ConnState, mailbox *imap.MailboxStatus) {
c.locker.Lock()
c.state = state
c.mailbox = mailbox
c.locker.Unlock()
} | go | func (c *Client) SetState(state imap.ConnState, mailbox *imap.MailboxStatus) {
c.locker.Lock()
c.state = state
c.mailbox = mailbox
c.locker.Unlock()
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SetState",
"(",
"state",
"imap",
".",
"ConnState",
",",
"mailbox",
"*",
"imap",
".",
"MailboxStatus",
")",
"{",
"c",
".",
"locker",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"state",
"=",
"state",
"\n",
"c",
".",
"mailbox",
"=",
"mailbox",
"\n",
"c",
".",
"locker",
".",
"Unlock",
"(",
")",
"\n",
"}"
]
| // SetState sets this connection's internal state.
//
// This function should not be called directly, it must only be used by
// libraries implementing extensions of the IMAP protocol. | [
"SetState",
"sets",
"this",
"connection",
"s",
"internal",
"state",
".",
"This",
"function",
"should",
"not",
"be",
"called",
"directly",
"it",
"must",
"only",
"be",
"used",
"by",
"libraries",
"implementing",
"extensions",
"of",
"the",
"IMAP",
"protocol",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/client.go#L298-L303 |
148,130 | emersion/go-imap | client/client.go | Execute | func (c *Client) Execute(cmdr imap.Commander, h responses.Handler) (*imap.StatusResp, error) {
return c.execute(cmdr, h)
} | go | func (c *Client) Execute(cmdr imap.Commander, h responses.Handler) (*imap.StatusResp, error) {
return c.execute(cmdr, h)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Execute",
"(",
"cmdr",
"imap",
".",
"Commander",
",",
"h",
"responses",
".",
"Handler",
")",
"(",
"*",
"imap",
".",
"StatusResp",
",",
"error",
")",
"{",
"return",
"c",
".",
"execute",
"(",
"cmdr",
",",
"h",
")",
"\n",
"}"
]
| // Execute executes a generic command. cmdr is a value that can be converted to
// a raw command and h is a response handler. The function returns when the
// command has completed or failed, in this case err is nil. A non-nil err value
// indicates a network error.
//
// This function should not be called directly, it must only be used by
// libraries implementing extensions of the IMAP protocol. | [
"Execute",
"executes",
"a",
"generic",
"command",
".",
"cmdr",
"is",
"a",
"value",
"that",
"can",
"be",
"converted",
"to",
"a",
"raw",
"command",
"and",
"h",
"is",
"a",
"response",
"handler",
".",
"The",
"function",
"returns",
"when",
"the",
"command",
"has",
"completed",
"or",
"failed",
"in",
"this",
"case",
"err",
"is",
"nil",
".",
"A",
"non",
"-",
"nil",
"err",
"value",
"indicates",
"a",
"network",
"error",
".",
"This",
"function",
"should",
"not",
"be",
"called",
"directly",
"it",
"must",
"only",
"be",
"used",
"by",
"libraries",
"implementing",
"extensions",
"of",
"the",
"IMAP",
"protocol",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/client.go#L312-L314 |
148,131 | emersion/go-imap | client/client.go | New | func New(conn net.Conn) (*Client, error) {
continues := make(chan bool)
w := imap.NewClientWriter(nil, continues)
r := imap.NewReader(nil)
c := &Client{
conn: imap.NewConn(conn, r, w),
replies: make(chan []byte),
loggedOut: make(chan struct{}),
state: imap.ConnectingState,
ErrorLog: log.New(os.Stderr, "imap/client: ", log.LstdFlags),
}
c.handleContinuationReqs(continues)
c.handleUnilateral()
err := c.handleGreetAndStartReading()
return c, err
} | go | func New(conn net.Conn) (*Client, error) {
continues := make(chan bool)
w := imap.NewClientWriter(nil, continues)
r := imap.NewReader(nil)
c := &Client{
conn: imap.NewConn(conn, r, w),
replies: make(chan []byte),
loggedOut: make(chan struct{}),
state: imap.ConnectingState,
ErrorLog: log.New(os.Stderr, "imap/client: ", log.LstdFlags),
}
c.handleContinuationReqs(continues)
c.handleUnilateral()
err := c.handleGreetAndStartReading()
return c, err
} | [
"func",
"New",
"(",
"conn",
"net",
".",
"Conn",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"continues",
":=",
"make",
"(",
"chan",
"bool",
")",
"\n",
"w",
":=",
"imap",
".",
"NewClientWriter",
"(",
"nil",
",",
"continues",
")",
"\n",
"r",
":=",
"imap",
".",
"NewReader",
"(",
"nil",
")",
"\n\n",
"c",
":=",
"&",
"Client",
"{",
"conn",
":",
"imap",
".",
"NewConn",
"(",
"conn",
",",
"r",
",",
"w",
")",
",",
"replies",
":",
"make",
"(",
"chan",
"[",
"]",
"byte",
")",
",",
"loggedOut",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"state",
":",
"imap",
".",
"ConnectingState",
",",
"ErrorLog",
":",
"log",
".",
"New",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
",",
"log",
".",
"LstdFlags",
")",
",",
"}",
"\n\n",
"c",
".",
"handleContinuationReqs",
"(",
"continues",
")",
"\n",
"c",
".",
"handleUnilateral",
"(",
")",
"\n",
"err",
":=",
"c",
".",
"handleGreetAndStartReading",
"(",
")",
"\n",
"return",
"c",
",",
"err",
"\n",
"}"
]
| // New creates a new client from an existing connection. | [
"New",
"creates",
"a",
"new",
"client",
"from",
"an",
"existing",
"connection",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/client.go#L558-L575 |
148,132 | emersion/go-imap | client/client.go | Dial | func Dial(addr string) (c *Client, err error) {
conn, err := net.Dial("tcp", addr)
if err != nil {
return
}
c, err = New(conn)
return
} | go | func Dial(addr string) (c *Client, err error) {
conn, err := net.Dial("tcp", addr)
if err != nil {
return
}
c, err = New(conn)
return
} | [
"func",
"Dial",
"(",
"addr",
"string",
")",
"(",
"c",
"*",
"Client",
",",
"err",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"net",
".",
"Dial",
"(",
"\"",
"\"",
",",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"c",
",",
"err",
"=",
"New",
"(",
"conn",
")",
"\n",
"return",
"\n",
"}"
]
| // Dial connects to an IMAP server using an unencrypted connection. | [
"Dial",
"connects",
"to",
"an",
"IMAP",
"server",
"using",
"an",
"unencrypted",
"connection",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/client.go#L578-L586 |
148,133 | emersion/go-imap | client/client.go | DialWithDialer | func DialWithDialer(dialer *net.Dialer, address string) (c *Client, err error) {
conn, err := dialer.Dial("tcp", address)
if err != nil {
return nil, err
}
// We don't return to the caller until we try to receive a greeting. As such,
// there is no way to set the client's Timeout for that action. As a
// workaround, if the dialer has a timeout set, use that for the connection's
// deadline.
if dialer.Timeout > 0 {
err = conn.SetDeadline(time.Now().Add(dialer.Timeout))
if err != nil {
return
}
}
c, err = New(conn)
return
} | go | func DialWithDialer(dialer *net.Dialer, address string) (c *Client, err error) {
conn, err := dialer.Dial("tcp", address)
if err != nil {
return nil, err
}
// We don't return to the caller until we try to receive a greeting. As such,
// there is no way to set the client's Timeout for that action. As a
// workaround, if the dialer has a timeout set, use that for the connection's
// deadline.
if dialer.Timeout > 0 {
err = conn.SetDeadline(time.Now().Add(dialer.Timeout))
if err != nil {
return
}
}
c, err = New(conn)
return
} | [
"func",
"DialWithDialer",
"(",
"dialer",
"*",
"net",
".",
"Dialer",
",",
"address",
"string",
")",
"(",
"c",
"*",
"Client",
",",
"err",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"dialer",
".",
"Dial",
"(",
"\"",
"\"",
",",
"address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// We don't return to the caller until we try to receive a greeting. As such,",
"// there is no way to set the client's Timeout for that action. As a",
"// workaround, if the dialer has a timeout set, use that for the connection's",
"// deadline.",
"if",
"dialer",
".",
"Timeout",
">",
"0",
"{",
"err",
"=",
"conn",
".",
"SetDeadline",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"dialer",
".",
"Timeout",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"c",
",",
"err",
"=",
"New",
"(",
"conn",
")",
"\n",
"return",
"\n",
"}"
]
| // DialWithDialer connects to an IMAP server using an unencrypted connection
// using dialer.Dial.
//
// Among other uses, this allows to apply a dial timeout. | [
"DialWithDialer",
"connects",
"to",
"an",
"IMAP",
"server",
"using",
"an",
"unencrypted",
"connection",
"using",
"dialer",
".",
"Dial",
".",
"Among",
"other",
"uses",
"this",
"allows",
"to",
"apply",
"a",
"dial",
"timeout",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/client.go#L592-L611 |
148,134 | emersion/go-imap | client/client.go | DialTLS | func DialTLS(addr string, tlsConfig *tls.Config) (c *Client, err error) {
conn, err := tls.Dial("tcp", addr, tlsConfig)
if err != nil {
return
}
c, err = New(conn)
c.isTLS = true
return
} | go | func DialTLS(addr string, tlsConfig *tls.Config) (c *Client, err error) {
conn, err := tls.Dial("tcp", addr, tlsConfig)
if err != nil {
return
}
c, err = New(conn)
c.isTLS = true
return
} | [
"func",
"DialTLS",
"(",
"addr",
"string",
",",
"tlsConfig",
"*",
"tls",
".",
"Config",
")",
"(",
"c",
"*",
"Client",
",",
"err",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"tls",
".",
"Dial",
"(",
"\"",
"\"",
",",
"addr",
",",
"tlsConfig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"c",
",",
"err",
"=",
"New",
"(",
"conn",
")",
"\n",
"c",
".",
"isTLS",
"=",
"true",
"\n",
"return",
"\n",
"}"
]
| // DialTLS connects to an IMAP server using an encrypted connection. | [
"DialTLS",
"connects",
"to",
"an",
"IMAP",
"server",
"using",
"an",
"encrypted",
"connection",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/client.go#L614-L623 |
148,135 | emersion/go-imap | client/client.go | DialWithDialerTLS | func DialWithDialerTLS(dialer *net.Dialer, addr string,
tlsConfig *tls.Config) (c *Client, err error) {
conn, err := tls.DialWithDialer(dialer, "tcp", addr, tlsConfig)
if err != nil {
return
}
// We don't return to the caller until we try to receive a greeting. As such,
// there is no way to set the client's Timeout for that action. As a
// workaround, if the dialer has a timeout set, use that for the connection's
// deadline.
if dialer.Timeout > 0 {
err = conn.SetDeadline(time.Now().Add(dialer.Timeout))
if err != nil {
return
}
}
c, err = New(conn)
c.isTLS = true
return
} | go | func DialWithDialerTLS(dialer *net.Dialer, addr string,
tlsConfig *tls.Config) (c *Client, err error) {
conn, err := tls.DialWithDialer(dialer, "tcp", addr, tlsConfig)
if err != nil {
return
}
// We don't return to the caller until we try to receive a greeting. As such,
// there is no way to set the client's Timeout for that action. As a
// workaround, if the dialer has a timeout set, use that for the connection's
// deadline.
if dialer.Timeout > 0 {
err = conn.SetDeadline(time.Now().Add(dialer.Timeout))
if err != nil {
return
}
}
c, err = New(conn)
c.isTLS = true
return
} | [
"func",
"DialWithDialerTLS",
"(",
"dialer",
"*",
"net",
".",
"Dialer",
",",
"addr",
"string",
",",
"tlsConfig",
"*",
"tls",
".",
"Config",
")",
"(",
"c",
"*",
"Client",
",",
"err",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"tls",
".",
"DialWithDialer",
"(",
"dialer",
",",
"\"",
"\"",
",",
"addr",
",",
"tlsConfig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"// We don't return to the caller until we try to receive a greeting. As such,",
"// there is no way to set the client's Timeout for that action. As a",
"// workaround, if the dialer has a timeout set, use that for the connection's",
"// deadline.",
"if",
"dialer",
".",
"Timeout",
">",
"0",
"{",
"err",
"=",
"conn",
".",
"SetDeadline",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"dialer",
".",
"Timeout",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"c",
",",
"err",
"=",
"New",
"(",
"conn",
")",
"\n",
"c",
".",
"isTLS",
"=",
"true",
"\n",
"return",
"\n",
"}"
]
| // DialWithDialerTLS connects to an IMAP server using an encrypted connection
// using dialer.Dial.
//
// Among other uses, this allows to apply a dial timeout. | [
"DialWithDialerTLS",
"connects",
"to",
"an",
"IMAP",
"server",
"using",
"an",
"encrypted",
"connection",
"using",
"dialer",
".",
"Dial",
".",
"Among",
"other",
"uses",
"this",
"allows",
"to",
"apply",
"a",
"dial",
"timeout",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/client.go#L629-L650 |
148,136 | emersion/go-imap | write.go | FormatStringList | func FormatStringList(list []string) (fields []interface{}) {
fields = make([]interface{}, len(list))
for i, v := range list {
fields[i] = v
}
return
} | go | func FormatStringList(list []string) (fields []interface{}) {
fields = make([]interface{}, len(list))
for i, v := range list {
fields[i] = v
}
return
} | [
"func",
"FormatStringList",
"(",
"list",
"[",
"]",
"string",
")",
"(",
"fields",
"[",
"]",
"interface",
"{",
"}",
")",
"{",
"fields",
"=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"list",
")",
")",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"list",
"{",
"fields",
"[",
"i",
"]",
"=",
"v",
"\n",
"}",
"\n",
"return",
"\n",
"}"
]
| // Convert a string list to a field list. | [
"Convert",
"a",
"string",
"list",
"to",
"a",
"field",
"list",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/write.go#L33-L39 |
148,137 | emersion/go-imap | write.go | isAscii | func isAscii(s string) bool {
for _, c := range s {
if c > unicode.MaxASCII || unicode.IsControl(c) {
return false
}
}
return true
} | go | func isAscii(s string) bool {
for _, c := range s {
if c > unicode.MaxASCII || unicode.IsControl(c) {
return false
}
}
return true
} | [
"func",
"isAscii",
"(",
"s",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"s",
"{",
"if",
"c",
">",
"unicode",
".",
"MaxASCII",
"||",
"unicode",
".",
"IsControl",
"(",
"c",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
]
| // Check if a string is 8-bit clean. | [
"Check",
"if",
"a",
"string",
"is",
"8",
"-",
"bit",
"clean",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/write.go#L42-L49 |
148,138 | emersion/go-imap | write.go | writeString | func (w *Writer) writeString(s string) error {
_, err := io.WriteString(w.Writer, s)
return err
} | go | func (w *Writer) writeString(s string) error {
_, err := io.WriteString(w.Writer, s)
return err
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"writeString",
"(",
"s",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"io",
".",
"WriteString",
"(",
"w",
".",
"Writer",
",",
"s",
")",
"\n",
"return",
"err",
"\n",
"}"
]
| // Helper function to write a string to w. | [
"Helper",
"function",
"to",
"write",
"a",
"string",
"to",
"w",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/write.go#L59-L62 |
148,139 | emersion/go-imap | utf7/decoder.go | decode | func decode(b64 []byte) []byte {
var b []byte
// Allocate a single block of memory large enough to store the Base64 data
// (if padding is required), UTF-16-BE bytes, and decoded UTF-8 bytes.
// Since a 2-byte UTF-16 sequence may expand into a 3-byte UTF-8 sequence,
// double the space allocation for UTF-8.
if n := len(b64); b64[n-1] == '=' {
return nil
} else if n&3 == 0 {
b = make([]byte, b64Enc.DecodedLen(n)*3)
} else {
n += 4 - n&3
b = make([]byte, n+b64Enc.DecodedLen(n)*3)
copy(b[copy(b, b64):n], []byte("=="))
b64, b = b[:n], b[n:]
}
// Decode Base64 into the first 1/3rd of b
n, err := b64Enc.Decode(b, b64)
if err != nil || n&1 == 1 {
return nil
}
// Decode UTF-16-BE into the remaining 2/3rds of b
b, s := b[:n], b[n:]
j := 0
for i := 0; i < n; i += 2 {
r := rune(b[i])<<8 | rune(b[i+1])
if utf16.IsSurrogate(r) {
if i += 2; i == n {
return nil
}
r2 := rune(b[i])<<8 | rune(b[i+1])
if r = utf16.DecodeRune(r, r2); r == repl {
return nil
}
} else if min <= r && r <= max {
return nil
}
j += utf8.EncodeRune(s[j:], r)
}
return s[:j]
} | go | func decode(b64 []byte) []byte {
var b []byte
// Allocate a single block of memory large enough to store the Base64 data
// (if padding is required), UTF-16-BE bytes, and decoded UTF-8 bytes.
// Since a 2-byte UTF-16 sequence may expand into a 3-byte UTF-8 sequence,
// double the space allocation for UTF-8.
if n := len(b64); b64[n-1] == '=' {
return nil
} else if n&3 == 0 {
b = make([]byte, b64Enc.DecodedLen(n)*3)
} else {
n += 4 - n&3
b = make([]byte, n+b64Enc.DecodedLen(n)*3)
copy(b[copy(b, b64):n], []byte("=="))
b64, b = b[:n], b[n:]
}
// Decode Base64 into the first 1/3rd of b
n, err := b64Enc.Decode(b, b64)
if err != nil || n&1 == 1 {
return nil
}
// Decode UTF-16-BE into the remaining 2/3rds of b
b, s := b[:n], b[n:]
j := 0
for i := 0; i < n; i += 2 {
r := rune(b[i])<<8 | rune(b[i+1])
if utf16.IsSurrogate(r) {
if i += 2; i == n {
return nil
}
r2 := rune(b[i])<<8 | rune(b[i+1])
if r = utf16.DecodeRune(r, r2); r == repl {
return nil
}
} else if min <= r && r <= max {
return nil
}
j += utf8.EncodeRune(s[j:], r)
}
return s[:j]
} | [
"func",
"decode",
"(",
"b64",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"var",
"b",
"[",
"]",
"byte",
"\n\n",
"// Allocate a single block of memory large enough to store the Base64 data",
"// (if padding is required), UTF-16-BE bytes, and decoded UTF-8 bytes.",
"// Since a 2-byte UTF-16 sequence may expand into a 3-byte UTF-8 sequence,",
"// double the space allocation for UTF-8.",
"if",
"n",
":=",
"len",
"(",
"b64",
")",
";",
"b64",
"[",
"n",
"-",
"1",
"]",
"==",
"'='",
"{",
"return",
"nil",
"\n",
"}",
"else",
"if",
"n",
"&",
"3",
"==",
"0",
"{",
"b",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"b64Enc",
".",
"DecodedLen",
"(",
"n",
")",
"*",
"3",
")",
"\n",
"}",
"else",
"{",
"n",
"+=",
"4",
"-",
"n",
"&",
"3",
"\n",
"b",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"n",
"+",
"b64Enc",
".",
"DecodedLen",
"(",
"n",
")",
"*",
"3",
")",
"\n",
"copy",
"(",
"b",
"[",
"copy",
"(",
"b",
",",
"b64",
")",
":",
"n",
"]",
",",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
"\n",
"b64",
",",
"b",
"=",
"b",
"[",
":",
"n",
"]",
",",
"b",
"[",
"n",
":",
"]",
"\n",
"}",
"\n\n",
"// Decode Base64 into the first 1/3rd of b",
"n",
",",
"err",
":=",
"b64Enc",
".",
"Decode",
"(",
"b",
",",
"b64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"n",
"&",
"1",
"==",
"1",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Decode UTF-16-BE into the remaining 2/3rds of b",
"b",
",",
"s",
":=",
"b",
"[",
":",
"n",
"]",
",",
"b",
"[",
"n",
":",
"]",
"\n",
"j",
":=",
"0",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"+=",
"2",
"{",
"r",
":=",
"rune",
"(",
"b",
"[",
"i",
"]",
")",
"<<",
"8",
"|",
"rune",
"(",
"b",
"[",
"i",
"+",
"1",
"]",
")",
"\n",
"if",
"utf16",
".",
"IsSurrogate",
"(",
"r",
")",
"{",
"if",
"i",
"+=",
"2",
";",
"i",
"==",
"n",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"r2",
":=",
"rune",
"(",
"b",
"[",
"i",
"]",
")",
"<<",
"8",
"|",
"rune",
"(",
"b",
"[",
"i",
"+",
"1",
"]",
")",
"\n",
"if",
"r",
"=",
"utf16",
".",
"DecodeRune",
"(",
"r",
",",
"r2",
")",
";",
"r",
"==",
"repl",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"else",
"if",
"min",
"<=",
"r",
"&&",
"r",
"<=",
"max",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"j",
"+=",
"utf8",
".",
"EncodeRune",
"(",
"s",
"[",
"j",
":",
"]",
",",
"r",
")",
"\n",
"}",
"\n",
"return",
"s",
"[",
":",
"j",
"]",
"\n",
"}"
]
| // Extracts UTF-16-BE bytes from base64 data and converts them to UTF-8.
// A nil slice is returned if the encoding is invalid. | [
"Extracts",
"UTF",
"-",
"16",
"-",
"BE",
"bytes",
"from",
"base64",
"data",
"and",
"converts",
"them",
"to",
"UTF",
"-",
"8",
".",
"A",
"nil",
"slice",
"is",
"returned",
"if",
"the",
"encoding",
"is",
"invalid",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/utf7/decoder.go#L105-L148 |
148,140 | emersion/go-imap | imap.go | Expand | func (item FetchItem) Expand() []FetchItem {
switch item {
case FetchAll:
return []FetchItem{FetchFlags, FetchInternalDate, FetchRFC822Size, FetchEnvelope}
case FetchFast:
return []FetchItem{FetchFlags, FetchInternalDate, FetchRFC822Size}
case FetchFull:
return []FetchItem{FetchFlags, FetchInternalDate, FetchRFC822Size, FetchEnvelope, FetchBody}
default:
return []FetchItem{item}
}
} | go | func (item FetchItem) Expand() []FetchItem {
switch item {
case FetchAll:
return []FetchItem{FetchFlags, FetchInternalDate, FetchRFC822Size, FetchEnvelope}
case FetchFast:
return []FetchItem{FetchFlags, FetchInternalDate, FetchRFC822Size}
case FetchFull:
return []FetchItem{FetchFlags, FetchInternalDate, FetchRFC822Size, FetchEnvelope, FetchBody}
default:
return []FetchItem{item}
}
} | [
"func",
"(",
"item",
"FetchItem",
")",
"Expand",
"(",
")",
"[",
"]",
"FetchItem",
"{",
"switch",
"item",
"{",
"case",
"FetchAll",
":",
"return",
"[",
"]",
"FetchItem",
"{",
"FetchFlags",
",",
"FetchInternalDate",
",",
"FetchRFC822Size",
",",
"FetchEnvelope",
"}",
"\n",
"case",
"FetchFast",
":",
"return",
"[",
"]",
"FetchItem",
"{",
"FetchFlags",
",",
"FetchInternalDate",
",",
"FetchRFC822Size",
"}",
"\n",
"case",
"FetchFull",
":",
"return",
"[",
"]",
"FetchItem",
"{",
"FetchFlags",
",",
"FetchInternalDate",
",",
"FetchRFC822Size",
",",
"FetchEnvelope",
",",
"FetchBody",
"}",
"\n",
"default",
":",
"return",
"[",
"]",
"FetchItem",
"{",
"item",
"}",
"\n",
"}",
"\n",
"}"
]
| // Expand expands the item if it's a macro. | [
"Expand",
"expands",
"the",
"item",
"if",
"it",
"s",
"a",
"macro",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/imap.go#L46-L57 |
148,141 | emersion/go-imap | imap.go | FormatFlagsOp | func FormatFlagsOp(op FlagsOp, silent bool) StoreItem {
s := string(op)
if silent {
s += silentOp
}
return StoreItem(s)
} | go | func FormatFlagsOp(op FlagsOp, silent bool) StoreItem {
s := string(op)
if silent {
s += silentOp
}
return StoreItem(s)
} | [
"func",
"FormatFlagsOp",
"(",
"op",
"FlagsOp",
",",
"silent",
"bool",
")",
"StoreItem",
"{",
"s",
":=",
"string",
"(",
"op",
")",
"\n",
"if",
"silent",
"{",
"s",
"+=",
"silentOp",
"\n",
"}",
"\n",
"return",
"StoreItem",
"(",
"s",
")",
"\n",
"}"
]
| // FormatFlagsOp returns the StoreItem that executes the flags operation op. | [
"FormatFlagsOp",
"returns",
"the",
"StoreItem",
"that",
"executes",
"the",
"flags",
"operation",
"op",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/imap.go#L79-L85 |
148,142 | emersion/go-imap | imap.go | ParseFlagsOp | func ParseFlagsOp(item StoreItem) (op FlagsOp, silent bool, err error) {
itemStr := string(item)
silent = strings.HasSuffix(itemStr, silentOp)
if silent {
itemStr = strings.TrimSuffix(itemStr, silentOp)
}
op = FlagsOp(itemStr)
if op != SetFlags && op != AddFlags && op != RemoveFlags {
err = errors.New("Unsupported STORE operation")
}
return
} | go | func ParseFlagsOp(item StoreItem) (op FlagsOp, silent bool, err error) {
itemStr := string(item)
silent = strings.HasSuffix(itemStr, silentOp)
if silent {
itemStr = strings.TrimSuffix(itemStr, silentOp)
}
op = FlagsOp(itemStr)
if op != SetFlags && op != AddFlags && op != RemoveFlags {
err = errors.New("Unsupported STORE operation")
}
return
} | [
"func",
"ParseFlagsOp",
"(",
"item",
"StoreItem",
")",
"(",
"op",
"FlagsOp",
",",
"silent",
"bool",
",",
"err",
"error",
")",
"{",
"itemStr",
":=",
"string",
"(",
"item",
")",
"\n",
"silent",
"=",
"strings",
".",
"HasSuffix",
"(",
"itemStr",
",",
"silentOp",
")",
"\n",
"if",
"silent",
"{",
"itemStr",
"=",
"strings",
".",
"TrimSuffix",
"(",
"itemStr",
",",
"silentOp",
")",
"\n",
"}",
"\n",
"op",
"=",
"FlagsOp",
"(",
"itemStr",
")",
"\n\n",
"if",
"op",
"!=",
"SetFlags",
"&&",
"op",
"!=",
"AddFlags",
"&&",
"op",
"!=",
"RemoveFlags",
"{",
"err",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
]
| // ParseFlagsOp parses a flags operation from StoreItem. | [
"ParseFlagsOp",
"parses",
"a",
"flags",
"operation",
"from",
"StoreItem",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/imap.go#L88-L100 |
148,143 | emersion/go-imap | client/cmd_any.go | Capability | func (c *Client) Capability() (map[string]bool, error) {
cmd := &commands.Capability{}
if status, err := c.execute(cmd, nil); err != nil {
return nil, err
} else if err := status.Err(); err != nil {
return nil, err
}
c.locker.Lock()
caps := c.caps
c.locker.Unlock()
return caps, nil
} | go | func (c *Client) Capability() (map[string]bool, error) {
cmd := &commands.Capability{}
if status, err := c.execute(cmd, nil); err != nil {
return nil, err
} else if err := status.Err(); err != nil {
return nil, err
}
c.locker.Lock()
caps := c.caps
c.locker.Unlock()
return caps, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Capability",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"bool",
",",
"error",
")",
"{",
"cmd",
":=",
"&",
"commands",
".",
"Capability",
"{",
"}",
"\n\n",
"if",
"status",
",",
"err",
":=",
"c",
".",
"execute",
"(",
"cmd",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"if",
"err",
":=",
"status",
".",
"Err",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"c",
".",
"locker",
".",
"Lock",
"(",
")",
"\n",
"caps",
":=",
"c",
".",
"caps",
"\n",
"c",
".",
"locker",
".",
"Unlock",
"(",
")",
"\n",
"return",
"caps",
",",
"nil",
"\n",
"}"
]
| // Capability requests a listing of capabilities that the server supports.
// Capabilities are often returned by the server with the greeting or with the
// STARTTLS and LOGIN responses, so usually explicitly requesting capabilities
// isn't needed.
//
// Most of the time, Support should be used instead. | [
"Capability",
"requests",
"a",
"listing",
"of",
"capabilities",
"that",
"the",
"server",
"supports",
".",
"Capabilities",
"are",
"often",
"returned",
"by",
"the",
"server",
"with",
"the",
"greeting",
"or",
"with",
"the",
"STARTTLS",
"and",
"LOGIN",
"responses",
"so",
"usually",
"explicitly",
"requesting",
"capabilities",
"isn",
"t",
"needed",
".",
"Most",
"of",
"the",
"time",
"Support",
"should",
"be",
"used",
"instead",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_any.go#L20-L33 |
148,144 | emersion/go-imap | client/cmd_any.go | Support | func (c *Client) Support(cap string) (bool, error) {
c.locker.Lock()
ok := c.caps != nil
c.locker.Unlock()
// If capabilities are not cached, request them
if !ok {
if _, err := c.Capability(); err != nil {
return false, err
}
}
c.locker.Lock()
supported := c.caps[cap]
c.locker.Unlock()
return supported, nil
} | go | func (c *Client) Support(cap string) (bool, error) {
c.locker.Lock()
ok := c.caps != nil
c.locker.Unlock()
// If capabilities are not cached, request them
if !ok {
if _, err := c.Capability(); err != nil {
return false, err
}
}
c.locker.Lock()
supported := c.caps[cap]
c.locker.Unlock()
return supported, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Support",
"(",
"cap",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"c",
".",
"locker",
".",
"Lock",
"(",
")",
"\n",
"ok",
":=",
"c",
".",
"caps",
"!=",
"nil",
"\n",
"c",
".",
"locker",
".",
"Unlock",
"(",
")",
"\n\n",
"// If capabilities are not cached, request them",
"if",
"!",
"ok",
"{",
"if",
"_",
",",
"err",
":=",
"c",
".",
"Capability",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"c",
".",
"locker",
".",
"Lock",
"(",
")",
"\n",
"supported",
":=",
"c",
".",
"caps",
"[",
"cap",
"]",
"\n",
"c",
".",
"locker",
".",
"Unlock",
"(",
")",
"\n",
"return",
"supported",
",",
"nil",
"\n",
"}"
]
| // Support checks if cap is a capability supported by the server. If the server
// hasn't sent its capabilities yet, Support requests them. | [
"Support",
"checks",
"if",
"cap",
"is",
"a",
"capability",
"supported",
"by",
"the",
"server",
".",
"If",
"the",
"server",
"hasn",
"t",
"sent",
"its",
"capabilities",
"yet",
"Support",
"requests",
"them",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_any.go#L37-L53 |
148,145 | emersion/go-imap | client/cmd_any.go | Noop | func (c *Client) Noop() error {
cmd := new(commands.Noop)
status, err := c.execute(cmd, nil)
if err != nil {
return err
}
return status.Err()
} | go | func (c *Client) Noop() error {
cmd := new(commands.Noop)
status, err := c.execute(cmd, nil)
if err != nil {
return err
}
return status.Err()
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Noop",
"(",
")",
"error",
"{",
"cmd",
":=",
"new",
"(",
"commands",
".",
"Noop",
")",
"\n\n",
"status",
",",
"err",
":=",
"c",
".",
"execute",
"(",
"cmd",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"status",
".",
"Err",
"(",
")",
"\n",
"}"
]
| // Noop always succeeds and does nothing.
//
// It can be used as a periodic poll for new messages or message status updates
// during a period of inactivity. It can also be used to reset any inactivity
// autologout timer on the server. | [
"Noop",
"always",
"succeeds",
"and",
"does",
"nothing",
".",
"It",
"can",
"be",
"used",
"as",
"a",
"periodic",
"poll",
"for",
"new",
"messages",
"or",
"message",
"status",
"updates",
"during",
"a",
"period",
"of",
"inactivity",
".",
"It",
"can",
"also",
"be",
"used",
"to",
"reset",
"any",
"inactivity",
"autologout",
"timer",
"on",
"the",
"server",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_any.go#L60-L68 |
148,146 | emersion/go-imap | client/cmd_any.go | Logout | func (c *Client) Logout() error {
if c.State() == imap.LogoutState {
return ErrAlreadyLoggedOut
}
cmd := new(commands.Logout)
if status, err := c.execute(cmd, nil); err == errClosed {
// Server closed connection, that's what we want anyway
return nil
} else if err != nil {
return err
} else if status != nil {
return status.Err()
}
return nil
} | go | func (c *Client) Logout() error {
if c.State() == imap.LogoutState {
return ErrAlreadyLoggedOut
}
cmd := new(commands.Logout)
if status, err := c.execute(cmd, nil); err == errClosed {
// Server closed connection, that's what we want anyway
return nil
} else if err != nil {
return err
} else if status != nil {
return status.Err()
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Logout",
"(",
")",
"error",
"{",
"if",
"c",
".",
"State",
"(",
")",
"==",
"imap",
".",
"LogoutState",
"{",
"return",
"ErrAlreadyLoggedOut",
"\n",
"}",
"\n\n",
"cmd",
":=",
"new",
"(",
"commands",
".",
"Logout",
")",
"\n\n",
"if",
"status",
",",
"err",
":=",
"c",
".",
"execute",
"(",
"cmd",
",",
"nil",
")",
";",
"err",
"==",
"errClosed",
"{",
"// Server closed connection, that's what we want anyway",
"return",
"nil",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"else",
"if",
"status",
"!=",
"nil",
"{",
"return",
"status",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Logout gracefully closes the connection. | [
"Logout",
"gracefully",
"closes",
"the",
"connection",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_any.go#L71-L87 |
148,147 | emersion/go-imap | client/cmd_selected.go | Check | func (c *Client) Check() error {
if c.State() != imap.SelectedState {
return ErrNoMailboxSelected
}
cmd := new(commands.Check)
status, err := c.execute(cmd, nil)
if err != nil {
return err
}
return status.Err()
} | go | func (c *Client) Check() error {
if c.State() != imap.SelectedState {
return ErrNoMailboxSelected
}
cmd := new(commands.Check)
status, err := c.execute(cmd, nil)
if err != nil {
return err
}
return status.Err()
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Check",
"(",
")",
"error",
"{",
"if",
"c",
".",
"State",
"(",
")",
"!=",
"imap",
".",
"SelectedState",
"{",
"return",
"ErrNoMailboxSelected",
"\n",
"}",
"\n\n",
"cmd",
":=",
"new",
"(",
"commands",
".",
"Check",
")",
"\n\n",
"status",
",",
"err",
":=",
"c",
".",
"execute",
"(",
"cmd",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"status",
".",
"Err",
"(",
")",
"\n",
"}"
]
| // Check requests a checkpoint of the currently selected mailbox. A checkpoint
// refers to any implementation-dependent housekeeping associated with the
// mailbox that is not normally executed as part of each command. | [
"Check",
"requests",
"a",
"checkpoint",
"of",
"the",
"currently",
"selected",
"mailbox",
".",
"A",
"checkpoint",
"refers",
"to",
"any",
"implementation",
"-",
"dependent",
"housekeeping",
"associated",
"with",
"the",
"mailbox",
"that",
"is",
"not",
"normally",
"executed",
"as",
"part",
"of",
"each",
"command",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_selected.go#L18-L31 |
148,148 | emersion/go-imap | client/cmd_selected.go | Close | func (c *Client) Close() error {
if c.State() != imap.SelectedState {
return ErrNoMailboxSelected
}
cmd := new(commands.Close)
status, err := c.execute(cmd, nil)
if err != nil {
return err
} else if err := status.Err(); err != nil {
return err
}
c.locker.Lock()
c.state = imap.AuthenticatedState
c.mailbox = nil
c.locker.Unlock()
return nil
} | go | func (c *Client) Close() error {
if c.State() != imap.SelectedState {
return ErrNoMailboxSelected
}
cmd := new(commands.Close)
status, err := c.execute(cmd, nil)
if err != nil {
return err
} else if err := status.Err(); err != nil {
return err
}
c.locker.Lock()
c.state = imap.AuthenticatedState
c.mailbox = nil
c.locker.Unlock()
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"c",
".",
"State",
"(",
")",
"!=",
"imap",
".",
"SelectedState",
"{",
"return",
"ErrNoMailboxSelected",
"\n",
"}",
"\n\n",
"cmd",
":=",
"new",
"(",
"commands",
".",
"Close",
")",
"\n\n",
"status",
",",
"err",
":=",
"c",
".",
"execute",
"(",
"cmd",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"else",
"if",
"err",
":=",
"status",
".",
"Err",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"c",
".",
"locker",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"state",
"=",
"imap",
".",
"AuthenticatedState",
"\n",
"c",
".",
"mailbox",
"=",
"nil",
"\n",
"c",
".",
"locker",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Close permanently removes all messages that have the \Deleted flag set from
// the currently selected mailbox, and returns to the authenticated state from
// the selected state. | [
"Close",
"permanently",
"removes",
"all",
"messages",
"that",
"have",
"the",
"\\",
"Deleted",
"flag",
"set",
"from",
"the",
"currently",
"selected",
"mailbox",
"and",
"returns",
"to",
"the",
"authenticated",
"state",
"from",
"the",
"selected",
"state",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_selected.go#L36-L55 |
148,149 | emersion/go-imap | client/cmd_selected.go | Expunge | func (c *Client) Expunge(ch chan uint32) error {
if c.State() != imap.SelectedState {
return ErrNoMailboxSelected
}
cmd := new(commands.Expunge)
var h responses.Handler
if ch != nil {
h = &responses.Expunge{SeqNums: ch}
defer close(ch)
}
status, err := c.execute(cmd, h)
if err != nil {
return err
}
return status.Err()
} | go | func (c *Client) Expunge(ch chan uint32) error {
if c.State() != imap.SelectedState {
return ErrNoMailboxSelected
}
cmd := new(commands.Expunge)
var h responses.Handler
if ch != nil {
h = &responses.Expunge{SeqNums: ch}
defer close(ch)
}
status, err := c.execute(cmd, h)
if err != nil {
return err
}
return status.Err()
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Expunge",
"(",
"ch",
"chan",
"uint32",
")",
"error",
"{",
"if",
"c",
".",
"State",
"(",
")",
"!=",
"imap",
".",
"SelectedState",
"{",
"return",
"ErrNoMailboxSelected",
"\n",
"}",
"\n\n",
"cmd",
":=",
"new",
"(",
"commands",
".",
"Expunge",
")",
"\n\n",
"var",
"h",
"responses",
".",
"Handler",
"\n",
"if",
"ch",
"!=",
"nil",
"{",
"h",
"=",
"&",
"responses",
".",
"Expunge",
"{",
"SeqNums",
":",
"ch",
"}",
"\n",
"defer",
"close",
"(",
"ch",
")",
"\n",
"}",
"\n\n",
"status",
",",
"err",
":=",
"c",
".",
"execute",
"(",
"cmd",
",",
"h",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"status",
".",
"Err",
"(",
")",
"\n",
"}"
]
| // Expunge permanently removes all messages that have the \Deleted flag set from
// the currently selected mailbox. If ch is not nil, sends sequence IDs of each
// deleted message to this channel. | [
"Expunge",
"permanently",
"removes",
"all",
"messages",
"that",
"have",
"the",
"\\",
"Deleted",
"flag",
"set",
"from",
"the",
"currently",
"selected",
"mailbox",
".",
"If",
"ch",
"is",
"not",
"nil",
"sends",
"sequence",
"IDs",
"of",
"each",
"deleted",
"message",
"to",
"this",
"channel",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_selected.go#L65-L83 |
148,150 | emersion/go-imap | client/cmd_selected.go | UidSearch | func (c *Client) UidSearch(criteria *imap.SearchCriteria) (uids []uint32, err error) {
return c.search(true, criteria)
} | go | func (c *Client) UidSearch(criteria *imap.SearchCriteria) (uids []uint32, err error) {
return c.search(true, criteria)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"UidSearch",
"(",
"criteria",
"*",
"imap",
".",
"SearchCriteria",
")",
"(",
"uids",
"[",
"]",
"uint32",
",",
"err",
"error",
")",
"{",
"return",
"c",
".",
"search",
"(",
"true",
",",
"criteria",
")",
"\n",
"}"
]
| // UidSearch is identical to Search, but UIDs are returned instead of message
// sequence numbers. | [
"UidSearch",
"is",
"identical",
"to",
"Search",
"but",
"UIDs",
"are",
"returned",
"instead",
"of",
"message",
"sequence",
"numbers",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_selected.go#L132-L134 |
148,151 | emersion/go-imap | client/cmd_selected.go | Fetch | func (c *Client) Fetch(seqset *imap.SeqSet, items []imap.FetchItem, ch chan *imap.Message) error {
return c.fetch(false, seqset, items, ch)
} | go | func (c *Client) Fetch(seqset *imap.SeqSet, items []imap.FetchItem, ch chan *imap.Message) error {
return c.fetch(false, seqset, items, ch)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Fetch",
"(",
"seqset",
"*",
"imap",
".",
"SeqSet",
",",
"items",
"[",
"]",
"imap",
".",
"FetchItem",
",",
"ch",
"chan",
"*",
"imap",
".",
"Message",
")",
"error",
"{",
"return",
"c",
".",
"fetch",
"(",
"false",
",",
"seqset",
",",
"items",
",",
"ch",
")",
"\n",
"}"
]
| // Fetch retrieves data associated with a message in the mailbox. See RFC 3501
// section 6.4.5 for a list of items that can be requested. | [
"Fetch",
"retrieves",
"data",
"associated",
"with",
"a",
"message",
"in",
"the",
"mailbox",
".",
"See",
"RFC",
"3501",
"section",
"6",
".",
"4",
".",
"5",
"for",
"a",
"list",
"of",
"items",
"that",
"can",
"be",
"requested",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_selected.go#L162-L164 |
148,152 | emersion/go-imap | client/cmd_selected.go | UidFetch | func (c *Client) UidFetch(seqset *imap.SeqSet, items []imap.FetchItem, ch chan *imap.Message) error {
return c.fetch(true, seqset, items, ch)
} | go | func (c *Client) UidFetch(seqset *imap.SeqSet, items []imap.FetchItem, ch chan *imap.Message) error {
return c.fetch(true, seqset, items, ch)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"UidFetch",
"(",
"seqset",
"*",
"imap",
".",
"SeqSet",
",",
"items",
"[",
"]",
"imap",
".",
"FetchItem",
",",
"ch",
"chan",
"*",
"imap",
".",
"Message",
")",
"error",
"{",
"return",
"c",
".",
"fetch",
"(",
"true",
",",
"seqset",
",",
"items",
",",
"ch",
")",
"\n",
"}"
]
| // UidFetch is identical to Fetch, but seqset is interpreted as containing
// unique identifiers instead of message sequence numbers. | [
"UidFetch",
"is",
"identical",
"to",
"Fetch",
"but",
"seqset",
"is",
"interpreted",
"as",
"containing",
"unique",
"identifiers",
"instead",
"of",
"message",
"sequence",
"numbers",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_selected.go#L168-L170 |
148,153 | emersion/go-imap | client/cmd_selected.go | Store | func (c *Client) Store(seqset *imap.SeqSet, item imap.StoreItem, value interface{}, ch chan *imap.Message) error {
return c.store(false, seqset, item, value, ch)
} | go | func (c *Client) Store(seqset *imap.SeqSet, item imap.StoreItem, value interface{}, ch chan *imap.Message) error {
return c.store(false, seqset, item, value, ch)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Store",
"(",
"seqset",
"*",
"imap",
".",
"SeqSet",
",",
"item",
"imap",
".",
"StoreItem",
",",
"value",
"interface",
"{",
"}",
",",
"ch",
"chan",
"*",
"imap",
".",
"Message",
")",
"error",
"{",
"return",
"c",
".",
"store",
"(",
"false",
",",
"seqset",
",",
"item",
",",
"value",
",",
"ch",
")",
"\n",
"}"
]
| // Store alters data associated with a message in the mailbox. If ch is not nil,
// the updated value of the data will be sent to this channel. See RFC 3501
// section 6.4.6 for a list of items that can be updated. | [
"Store",
"alters",
"data",
"associated",
"with",
"a",
"message",
"in",
"the",
"mailbox",
".",
"If",
"ch",
"is",
"not",
"nil",
"the",
"updated",
"value",
"of",
"the",
"data",
"will",
"be",
"sent",
"to",
"this",
"channel",
".",
"See",
"RFC",
"3501",
"section",
"6",
".",
"4",
".",
"6",
"for",
"a",
"list",
"of",
"items",
"that",
"can",
"be",
"updated",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_selected.go#L220-L222 |
148,154 | emersion/go-imap | client/cmd_selected.go | UidStore | func (c *Client) UidStore(seqset *imap.SeqSet, item imap.StoreItem, value interface{}, ch chan *imap.Message) error {
return c.store(true, seqset, item, value, ch)
} | go | func (c *Client) UidStore(seqset *imap.SeqSet, item imap.StoreItem, value interface{}, ch chan *imap.Message) error {
return c.store(true, seqset, item, value, ch)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"UidStore",
"(",
"seqset",
"*",
"imap",
".",
"SeqSet",
",",
"item",
"imap",
".",
"StoreItem",
",",
"value",
"interface",
"{",
"}",
",",
"ch",
"chan",
"*",
"imap",
".",
"Message",
")",
"error",
"{",
"return",
"c",
".",
"store",
"(",
"true",
",",
"seqset",
",",
"item",
",",
"value",
",",
"ch",
")",
"\n",
"}"
]
| // UidStore is identical to Store, but seqset is interpreted as containing
// unique identifiers instead of message sequence numbers. | [
"UidStore",
"is",
"identical",
"to",
"Store",
"but",
"seqset",
"is",
"interpreted",
"as",
"containing",
"unique",
"identifiers",
"instead",
"of",
"message",
"sequence",
"numbers",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_selected.go#L226-L228 |
148,155 | emersion/go-imap | client/cmd_selected.go | UidCopy | func (c *Client) UidCopy(seqset *imap.SeqSet, dest string) error {
return c.copy(true, seqset, dest)
} | go | func (c *Client) UidCopy(seqset *imap.SeqSet, dest string) error {
return c.copy(true, seqset, dest)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"UidCopy",
"(",
"seqset",
"*",
"imap",
".",
"SeqSet",
",",
"dest",
"string",
")",
"error",
"{",
"return",
"c",
".",
"copy",
"(",
"true",
",",
"seqset",
",",
"dest",
")",
"\n",
"}"
]
| // UidCopy is identical to Copy, but seqset is interpreted as containing unique
// identifiers instead of message sequence numbers. | [
"UidCopy",
"is",
"identical",
"to",
"Copy",
"but",
"seqset",
"is",
"interpreted",
"as",
"containing",
"unique",
"identifiers",
"instead",
"of",
"message",
"sequence",
"numbers",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_selected.go#L258-L260 |
148,156 | emersion/go-imap | conn.go | NewDebugWriter | func NewDebugWriter(local, remote io.Writer) io.Writer {
return &debugWriter{Writer: local, local: local, remote: remote}
} | go | func NewDebugWriter(local, remote io.Writer) io.Writer {
return &debugWriter{Writer: local, local: local, remote: remote}
} | [
"func",
"NewDebugWriter",
"(",
"local",
",",
"remote",
"io",
".",
"Writer",
")",
"io",
".",
"Writer",
"{",
"return",
"&",
"debugWriter",
"{",
"Writer",
":",
"local",
",",
"local",
":",
"local",
",",
"remote",
":",
"remote",
"}",
"\n",
"}"
]
| // NewDebugWriter creates a new io.Writer that will write local network activity
// to local and remote network activity to remote. | [
"NewDebugWriter",
"creates",
"a",
"new",
"io",
".",
"Writer",
"that",
"will",
"write",
"local",
"network",
"activity",
"to",
"local",
"and",
"remote",
"network",
"activity",
"to",
"remote",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/conn.go#L117-L119 |
148,157 | emersion/go-imap | conn.go | NewConn | func NewConn(conn net.Conn, r *Reader, w *Writer) *Conn {
c := &Conn{Conn: conn, Reader: r, Writer: w}
c.init()
return c
} | go | func NewConn(conn net.Conn, r *Reader, w *Writer) *Conn {
c := &Conn{Conn: conn, Reader: r, Writer: w}
c.init()
return c
} | [
"func",
"NewConn",
"(",
"conn",
"net",
".",
"Conn",
",",
"r",
"*",
"Reader",
",",
"w",
"*",
"Writer",
")",
"*",
"Conn",
"{",
"c",
":=",
"&",
"Conn",
"{",
"Conn",
":",
"conn",
",",
"Reader",
":",
"r",
",",
"Writer",
":",
"w",
"}",
"\n\n",
"c",
".",
"init",
"(",
")",
"\n",
"return",
"c",
"\n",
"}"
]
| // NewConn creates a new IMAP connection. | [
"NewConn",
"creates",
"a",
"new",
"IMAP",
"connection",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/conn.go#L154-L159 |
148,158 | emersion/go-imap | seqset.go | Less | func (s Seq) Less(q uint32) bool {
return (s.Stop < q || q == 0) && s.Stop != 0
} | go | func (s Seq) Less(q uint32) bool {
return (s.Stop < q || q == 0) && s.Stop != 0
} | [
"func",
"(",
"s",
"Seq",
")",
"Less",
"(",
"q",
"uint32",
")",
"bool",
"{",
"return",
"(",
"s",
".",
"Stop",
"<",
"q",
"||",
"q",
"==",
"0",
")",
"&&",
"s",
".",
"Stop",
"!=",
"0",
"\n",
"}"
]
| // Less returns true if s precedes and does not contain seq-number q. | [
"Less",
"returns",
"true",
"if",
"s",
"precedes",
"and",
"does",
"not",
"contain",
"seq",
"-",
"number",
"q",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L65-L67 |
148,159 | emersion/go-imap | seqset.go | Merge | func (s Seq) Merge(t Seq) (union Seq, ok bool) {
if union = s; s == t {
ok = true
return
}
if s.Start != 0 && t.Start != 0 {
// s and t are any combination of "n", "n:m", or "n:*"
if s.Start > t.Start {
s, t = t, s
}
// s starts at or before t, check where it ends
if (s.Stop >= t.Stop && t.Stop != 0) || s.Stop == 0 {
return s, true // s is a superset of t
}
// s is "n" or "n:m", if m == ^uint32(0) then t is "n:*"
if s.Stop+1 >= t.Start || s.Stop == ^uint32(0) {
return Seq{s.Start, t.Stop}, true // s intersects or touches t
}
return
}
// exactly one of s and t is "*"
if s.Start == 0 {
if t.Stop == 0 {
return t, true // s is "*", t is "n:*"
}
} else if s.Stop == 0 {
return s, true // s is "n:*", t is "*"
}
return
} | go | func (s Seq) Merge(t Seq) (union Seq, ok bool) {
if union = s; s == t {
ok = true
return
}
if s.Start != 0 && t.Start != 0 {
// s and t are any combination of "n", "n:m", or "n:*"
if s.Start > t.Start {
s, t = t, s
}
// s starts at or before t, check where it ends
if (s.Stop >= t.Stop && t.Stop != 0) || s.Stop == 0 {
return s, true // s is a superset of t
}
// s is "n" or "n:m", if m == ^uint32(0) then t is "n:*"
if s.Stop+1 >= t.Start || s.Stop == ^uint32(0) {
return Seq{s.Start, t.Stop}, true // s intersects or touches t
}
return
}
// exactly one of s and t is "*"
if s.Start == 0 {
if t.Stop == 0 {
return t, true // s is "*", t is "n:*"
}
} else if s.Stop == 0 {
return s, true // s is "n:*", t is "*"
}
return
} | [
"func",
"(",
"s",
"Seq",
")",
"Merge",
"(",
"t",
"Seq",
")",
"(",
"union",
"Seq",
",",
"ok",
"bool",
")",
"{",
"if",
"union",
"=",
"s",
";",
"s",
"==",
"t",
"{",
"ok",
"=",
"true",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"s",
".",
"Start",
"!=",
"0",
"&&",
"t",
".",
"Start",
"!=",
"0",
"{",
"// s and t are any combination of \"n\", \"n:m\", or \"n:*\"",
"if",
"s",
".",
"Start",
">",
"t",
".",
"Start",
"{",
"s",
",",
"t",
"=",
"t",
",",
"s",
"\n",
"}",
"\n",
"// s starts at or before t, check where it ends",
"if",
"(",
"s",
".",
"Stop",
">=",
"t",
".",
"Stop",
"&&",
"t",
".",
"Stop",
"!=",
"0",
")",
"||",
"s",
".",
"Stop",
"==",
"0",
"{",
"return",
"s",
",",
"true",
"// s is a superset of t",
"\n",
"}",
"\n",
"// s is \"n\" or \"n:m\", if m == ^uint32(0) then t is \"n:*\"",
"if",
"s",
".",
"Stop",
"+",
"1",
">=",
"t",
".",
"Start",
"||",
"s",
".",
"Stop",
"==",
"^",
"uint32",
"(",
"0",
")",
"{",
"return",
"Seq",
"{",
"s",
".",
"Start",
",",
"t",
".",
"Stop",
"}",
",",
"true",
"// s intersects or touches t",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"// exactly one of s and t is \"*\"",
"if",
"s",
".",
"Start",
"==",
"0",
"{",
"if",
"t",
".",
"Stop",
"==",
"0",
"{",
"return",
"t",
",",
"true",
"// s is \"*\", t is \"n:*\"",
"\n",
"}",
"\n",
"}",
"else",
"if",
"s",
".",
"Stop",
"==",
"0",
"{",
"return",
"s",
",",
"true",
"// s is \"n:*\", t is \"*\"",
"\n",
"}",
"\n",
"return",
"\n",
"}"
]
| // Merge combines sequence values s and t into a single union if the two
// intersect or one is a superset of the other. The order of s and t does not
// matter. If the values cannot be merged, s is returned unmodified and ok is
// set to false. | [
"Merge",
"combines",
"sequence",
"values",
"s",
"and",
"t",
"into",
"a",
"single",
"union",
"if",
"the",
"two",
"intersect",
"or",
"one",
"is",
"a",
"superset",
"of",
"the",
"other",
".",
"The",
"order",
"of",
"s",
"and",
"t",
"does",
"not",
"matter",
".",
"If",
"the",
"values",
"cannot",
"be",
"merged",
"s",
"is",
"returned",
"unmodified",
"and",
"ok",
"is",
"set",
"to",
"false",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L73-L102 |
148,160 | emersion/go-imap | seqset.go | String | func (s Seq) String() string {
if s.Start == s.Stop {
if s.Start == 0 {
return "*"
}
return strconv.FormatUint(uint64(s.Start), 10)
}
b := strconv.AppendUint(make([]byte, 0, 24), uint64(s.Start), 10)
if s.Stop == 0 {
return string(append(b, ':', '*'))
}
return string(strconv.AppendUint(append(b, ':'), uint64(s.Stop), 10))
} | go | func (s Seq) String() string {
if s.Start == s.Stop {
if s.Start == 0 {
return "*"
}
return strconv.FormatUint(uint64(s.Start), 10)
}
b := strconv.AppendUint(make([]byte, 0, 24), uint64(s.Start), 10)
if s.Stop == 0 {
return string(append(b, ':', '*'))
}
return string(strconv.AppendUint(append(b, ':'), uint64(s.Stop), 10))
} | [
"func",
"(",
"s",
"Seq",
")",
"String",
"(",
")",
"string",
"{",
"if",
"s",
".",
"Start",
"==",
"s",
".",
"Stop",
"{",
"if",
"s",
".",
"Start",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"strconv",
".",
"FormatUint",
"(",
"uint64",
"(",
"s",
".",
"Start",
")",
",",
"10",
")",
"\n",
"}",
"\n",
"b",
":=",
"strconv",
".",
"AppendUint",
"(",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"24",
")",
",",
"uint64",
"(",
"s",
".",
"Start",
")",
",",
"10",
")",
"\n",
"if",
"s",
".",
"Stop",
"==",
"0",
"{",
"return",
"string",
"(",
"append",
"(",
"b",
",",
"':'",
",",
"'*'",
")",
")",
"\n",
"}",
"\n",
"return",
"string",
"(",
"strconv",
".",
"AppendUint",
"(",
"append",
"(",
"b",
",",
"':'",
")",
",",
"uint64",
"(",
"s",
".",
"Stop",
")",
",",
"10",
")",
")",
"\n",
"}"
]
| // String returns sequence value s as a seq-number or seq-range string. | [
"String",
"returns",
"sequence",
"value",
"s",
"as",
"a",
"seq",
"-",
"number",
"or",
"seq",
"-",
"range",
"string",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L105-L117 |
148,161 | emersion/go-imap | seqset.go | ParseSeqSet | func ParseSeqSet(set string) (s *SeqSet, err error) {
s = new(SeqSet)
return s, s.Add(set)
} | go | func ParseSeqSet(set string) (s *SeqSet, err error) {
s = new(SeqSet)
return s, s.Add(set)
} | [
"func",
"ParseSeqSet",
"(",
"set",
"string",
")",
"(",
"s",
"*",
"SeqSet",
",",
"err",
"error",
")",
"{",
"s",
"=",
"new",
"(",
"SeqSet",
")",
"\n",
"return",
"s",
",",
"s",
".",
"Add",
"(",
"set",
")",
"\n",
"}"
]
| // ParseSeqSet returns a new SeqSet instance after parsing the set string. | [
"ParseSeqSet",
"returns",
"a",
"new",
"SeqSet",
"instance",
"after",
"parsing",
"the",
"set",
"string",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L126-L129 |
148,162 | emersion/go-imap | seqset.go | Add | func (s *SeqSet) Add(set string) error {
for _, sv := range strings.Split(set, ",") {
v, err := parseSeq(sv)
if err != nil {
return err
}
s.insert(v)
}
return nil
} | go | func (s *SeqSet) Add(set string) error {
for _, sv := range strings.Split(set, ",") {
v, err := parseSeq(sv)
if err != nil {
return err
}
s.insert(v)
}
return nil
} | [
"func",
"(",
"s",
"*",
"SeqSet",
")",
"Add",
"(",
"set",
"string",
")",
"error",
"{",
"for",
"_",
",",
"sv",
":=",
"range",
"strings",
".",
"Split",
"(",
"set",
",",
"\"",
"\"",
")",
"{",
"v",
",",
"err",
":=",
"parseSeq",
"(",
"sv",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"s",
".",
"insert",
"(",
"v",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Add inserts new sequence values into the set. The string format is described
// by RFC 3501 sequence-set ABNF rule. If an error is encountered, all values
// inserted successfully prior to the error remain in the set. | [
"Add",
"inserts",
"new",
"sequence",
"values",
"into",
"the",
"set",
".",
"The",
"string",
"format",
"is",
"described",
"by",
"RFC",
"3501",
"sequence",
"-",
"set",
"ABNF",
"rule",
".",
"If",
"an",
"error",
"is",
"encountered",
"all",
"values",
"inserted",
"successfully",
"prior",
"to",
"the",
"error",
"remain",
"in",
"the",
"set",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L134-L143 |
148,163 | emersion/go-imap | seqset.go | AddRange | func (s *SeqSet) AddRange(Start, Stop uint32) {
if (Stop < Start && Stop != 0) || Start == 0 {
s.insert(Seq{Stop, Start})
} else {
s.insert(Seq{Start, Stop})
}
} | go | func (s *SeqSet) AddRange(Start, Stop uint32) {
if (Stop < Start && Stop != 0) || Start == 0 {
s.insert(Seq{Stop, Start})
} else {
s.insert(Seq{Start, Stop})
}
} | [
"func",
"(",
"s",
"*",
"SeqSet",
")",
"AddRange",
"(",
"Start",
",",
"Stop",
"uint32",
")",
"{",
"if",
"(",
"Stop",
"<",
"Start",
"&&",
"Stop",
"!=",
"0",
")",
"||",
"Start",
"==",
"0",
"{",
"s",
".",
"insert",
"(",
"Seq",
"{",
"Stop",
",",
"Start",
"}",
")",
"\n",
"}",
"else",
"{",
"s",
".",
"insert",
"(",
"Seq",
"{",
"Start",
",",
"Stop",
"}",
")",
"\n",
"}",
"\n",
"}"
]
| // AddRange inserts a new sequence range into the set. | [
"AddRange",
"inserts",
"a",
"new",
"sequence",
"range",
"into",
"the",
"set",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L153-L159 |
148,164 | emersion/go-imap | seqset.go | AddSet | func (s *SeqSet) AddSet(t *SeqSet) {
for _, v := range t.Set {
s.insert(v)
}
} | go | func (s *SeqSet) AddSet(t *SeqSet) {
for _, v := range t.Set {
s.insert(v)
}
} | [
"func",
"(",
"s",
"*",
"SeqSet",
")",
"AddSet",
"(",
"t",
"*",
"SeqSet",
")",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"t",
".",
"Set",
"{",
"s",
".",
"insert",
"(",
"v",
")",
"\n",
"}",
"\n",
"}"
]
| // AddSet inserts all values from t into s. | [
"AddSet",
"inserts",
"all",
"values",
"from",
"t",
"into",
"s",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L162-L166 |
148,165 | emersion/go-imap | seqset.go | String | func (s SeqSet) String() string {
if len(s.Set) == 0 {
return ""
}
b := make([]byte, 0, 64)
for _, v := range s.Set {
b = append(b, ',')
if v.Start == 0 {
b = append(b, '*')
continue
}
b = strconv.AppendUint(b, uint64(v.Start), 10)
if v.Start != v.Stop {
if v.Stop == 0 {
b = append(b, ':', '*')
continue
}
b = strconv.AppendUint(append(b, ':'), uint64(v.Stop), 10)
}
}
return string(b[1:])
} | go | func (s SeqSet) String() string {
if len(s.Set) == 0 {
return ""
}
b := make([]byte, 0, 64)
for _, v := range s.Set {
b = append(b, ',')
if v.Start == 0 {
b = append(b, '*')
continue
}
b = strconv.AppendUint(b, uint64(v.Start), 10)
if v.Start != v.Stop {
if v.Stop == 0 {
b = append(b, ':', '*')
continue
}
b = strconv.AppendUint(append(b, ':'), uint64(v.Stop), 10)
}
}
return string(b[1:])
} | [
"func",
"(",
"s",
"SeqSet",
")",
"String",
"(",
")",
"string",
"{",
"if",
"len",
"(",
"s",
".",
"Set",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"64",
")",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"s",
".",
"Set",
"{",
"b",
"=",
"append",
"(",
"b",
",",
"','",
")",
"\n",
"if",
"v",
".",
"Start",
"==",
"0",
"{",
"b",
"=",
"append",
"(",
"b",
",",
"'*'",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"b",
"=",
"strconv",
".",
"AppendUint",
"(",
"b",
",",
"uint64",
"(",
"v",
".",
"Start",
")",
",",
"10",
")",
"\n",
"if",
"v",
".",
"Start",
"!=",
"v",
".",
"Stop",
"{",
"if",
"v",
".",
"Stop",
"==",
"0",
"{",
"b",
"=",
"append",
"(",
"b",
",",
"':'",
",",
"'*'",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"b",
"=",
"strconv",
".",
"AppendUint",
"(",
"append",
"(",
"b",
",",
"':'",
")",
",",
"uint64",
"(",
"v",
".",
"Stop",
")",
",",
"10",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"string",
"(",
"b",
"[",
"1",
":",
"]",
")",
"\n",
"}"
]
| // String returns a sorted representation of all contained sequence values. | [
"String",
"returns",
"a",
"sorted",
"representation",
"of",
"all",
"contained",
"sequence",
"values",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L196-L217 |
148,166 | emersion/go-imap | seqset.go | insert | func (s *SeqSet) insert(v Seq) {
i, _ := s.search(v.Start)
merged := false
if i > 0 {
// try merging with the preceding entry (e.g. "1,4".insert(2), i == 1)
s.Set[i-1], merged = s.Set[i-1].Merge(v)
}
if i == len(s.Set) {
// v was either merged with the last entry or needs to be appended
if !merged {
s.insertAt(i, v)
}
return
} else if merged {
i--
} else if s.Set[i], merged = s.Set[i].Merge(v); !merged {
s.insertAt(i, v) // insert in the middle (e.g. "1,5".insert(3), i == 1)
return
}
// v was merged with s.Set[i], continue trying to merge until the end
for j := i + 1; j < len(s.Set); j++ {
if s.Set[i], merged = s.Set[i].Merge(s.Set[j]); !merged {
if j > i+1 {
// cut out all entries between i and j that were merged
s.Set = append(s.Set[:i+1], s.Set[j:]...)
}
return
}
}
// everything after s.Set[i] was merged
s.Set = s.Set[:i+1]
} | go | func (s *SeqSet) insert(v Seq) {
i, _ := s.search(v.Start)
merged := false
if i > 0 {
// try merging with the preceding entry (e.g. "1,4".insert(2), i == 1)
s.Set[i-1], merged = s.Set[i-1].Merge(v)
}
if i == len(s.Set) {
// v was either merged with the last entry or needs to be appended
if !merged {
s.insertAt(i, v)
}
return
} else if merged {
i--
} else if s.Set[i], merged = s.Set[i].Merge(v); !merged {
s.insertAt(i, v) // insert in the middle (e.g. "1,5".insert(3), i == 1)
return
}
// v was merged with s.Set[i], continue trying to merge until the end
for j := i + 1; j < len(s.Set); j++ {
if s.Set[i], merged = s.Set[i].Merge(s.Set[j]); !merged {
if j > i+1 {
// cut out all entries between i and j that were merged
s.Set = append(s.Set[:i+1], s.Set[j:]...)
}
return
}
}
// everything after s.Set[i] was merged
s.Set = s.Set[:i+1]
} | [
"func",
"(",
"s",
"*",
"SeqSet",
")",
"insert",
"(",
"v",
"Seq",
")",
"{",
"i",
",",
"_",
":=",
"s",
".",
"search",
"(",
"v",
".",
"Start",
")",
"\n",
"merged",
":=",
"false",
"\n",
"if",
"i",
">",
"0",
"{",
"// try merging with the preceding entry (e.g. \"1,4\".insert(2), i == 1)",
"s",
".",
"Set",
"[",
"i",
"-",
"1",
"]",
",",
"merged",
"=",
"s",
".",
"Set",
"[",
"i",
"-",
"1",
"]",
".",
"Merge",
"(",
"v",
")",
"\n",
"}",
"\n",
"if",
"i",
"==",
"len",
"(",
"s",
".",
"Set",
")",
"{",
"// v was either merged with the last entry or needs to be appended",
"if",
"!",
"merged",
"{",
"s",
".",
"insertAt",
"(",
"i",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"else",
"if",
"merged",
"{",
"i",
"--",
"\n",
"}",
"else",
"if",
"s",
".",
"Set",
"[",
"i",
"]",
",",
"merged",
"=",
"s",
".",
"Set",
"[",
"i",
"]",
".",
"Merge",
"(",
"v",
")",
";",
"!",
"merged",
"{",
"s",
".",
"insertAt",
"(",
"i",
",",
"v",
")",
"// insert in the middle (e.g. \"1,5\".insert(3), i == 1)",
"\n",
"return",
"\n",
"}",
"\n",
"// v was merged with s.Set[i], continue trying to merge until the end",
"for",
"j",
":=",
"i",
"+",
"1",
";",
"j",
"<",
"len",
"(",
"s",
".",
"Set",
")",
";",
"j",
"++",
"{",
"if",
"s",
".",
"Set",
"[",
"i",
"]",
",",
"merged",
"=",
"s",
".",
"Set",
"[",
"i",
"]",
".",
"Merge",
"(",
"s",
".",
"Set",
"[",
"j",
"]",
")",
";",
"!",
"merged",
"{",
"if",
"j",
">",
"i",
"+",
"1",
"{",
"// cut out all entries between i and j that were merged",
"s",
".",
"Set",
"=",
"append",
"(",
"s",
".",
"Set",
"[",
":",
"i",
"+",
"1",
"]",
",",
"s",
".",
"Set",
"[",
"j",
":",
"]",
"...",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"// everything after s.Set[i] was merged",
"s",
".",
"Set",
"=",
"s",
".",
"Set",
"[",
":",
"i",
"+",
"1",
"]",
"\n",
"}"
]
| // insert adds sequence value v to the set. | [
"insert",
"adds",
"sequence",
"value",
"v",
"to",
"the",
"set",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L220-L251 |
148,167 | emersion/go-imap | seqset.go | insertAt | func (s *SeqSet) insertAt(i int, v Seq) {
if n := len(s.Set); i == n {
// insert at the end
s.Set = append(s.Set, v)
return
} else if n < cap(s.Set) {
// enough space, shift everything at and after i to the right
s.Set = s.Set[:n+1]
copy(s.Set[i+1:], s.Set[i:])
} else {
// allocate new slice and copy everything, n is at least 1
set := make([]Seq, n+1, n*2)
copy(set, s.Set[:i])
copy(set[i+1:], s.Set[i:])
s.Set = set
}
s.Set[i] = v
} | go | func (s *SeqSet) insertAt(i int, v Seq) {
if n := len(s.Set); i == n {
// insert at the end
s.Set = append(s.Set, v)
return
} else if n < cap(s.Set) {
// enough space, shift everything at and after i to the right
s.Set = s.Set[:n+1]
copy(s.Set[i+1:], s.Set[i:])
} else {
// allocate new slice and copy everything, n is at least 1
set := make([]Seq, n+1, n*2)
copy(set, s.Set[:i])
copy(set[i+1:], s.Set[i:])
s.Set = set
}
s.Set[i] = v
} | [
"func",
"(",
"s",
"*",
"SeqSet",
")",
"insertAt",
"(",
"i",
"int",
",",
"v",
"Seq",
")",
"{",
"if",
"n",
":=",
"len",
"(",
"s",
".",
"Set",
")",
";",
"i",
"==",
"n",
"{",
"// insert at the end",
"s",
".",
"Set",
"=",
"append",
"(",
"s",
".",
"Set",
",",
"v",
")",
"\n",
"return",
"\n",
"}",
"else",
"if",
"n",
"<",
"cap",
"(",
"s",
".",
"Set",
")",
"{",
"// enough space, shift everything at and after i to the right",
"s",
".",
"Set",
"=",
"s",
".",
"Set",
"[",
":",
"n",
"+",
"1",
"]",
"\n",
"copy",
"(",
"s",
".",
"Set",
"[",
"i",
"+",
"1",
":",
"]",
",",
"s",
".",
"Set",
"[",
"i",
":",
"]",
")",
"\n",
"}",
"else",
"{",
"// allocate new slice and copy everything, n is at least 1",
"set",
":=",
"make",
"(",
"[",
"]",
"Seq",
",",
"n",
"+",
"1",
",",
"n",
"*",
"2",
")",
"\n",
"copy",
"(",
"set",
",",
"s",
".",
"Set",
"[",
":",
"i",
"]",
")",
"\n",
"copy",
"(",
"set",
"[",
"i",
"+",
"1",
":",
"]",
",",
"s",
".",
"Set",
"[",
"i",
":",
"]",
")",
"\n",
"s",
".",
"Set",
"=",
"set",
"\n",
"}",
"\n",
"s",
".",
"Set",
"[",
"i",
"]",
"=",
"v",
"\n",
"}"
]
| // insertAt inserts a new sequence value v at index i, resizing s.Set as needed. | [
"insertAt",
"inserts",
"a",
"new",
"sequence",
"value",
"v",
"at",
"index",
"i",
"resizing",
"s",
".",
"Set",
"as",
"needed",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L254-L271 |
148,168 | emersion/go-imap | seqset.go | search | func (s SeqSet) search(q uint32) (i int, ok bool) {
min, max := 0, len(s.Set)-1
for min < max {
if mid := (min + max) >> 1; s.Set[mid].Less(q) {
min = mid + 1
} else {
max = mid
}
}
if max < 0 || s.Set[min].Less(q) {
return len(s.Set), false // q is the new largest value
}
return min, s.Set[min].Contains(q)
} | go | func (s SeqSet) search(q uint32) (i int, ok bool) {
min, max := 0, len(s.Set)-1
for min < max {
if mid := (min + max) >> 1; s.Set[mid].Less(q) {
min = mid + 1
} else {
max = mid
}
}
if max < 0 || s.Set[min].Less(q) {
return len(s.Set), false // q is the new largest value
}
return min, s.Set[min].Contains(q)
} | [
"func",
"(",
"s",
"SeqSet",
")",
"search",
"(",
"q",
"uint32",
")",
"(",
"i",
"int",
",",
"ok",
"bool",
")",
"{",
"min",
",",
"max",
":=",
"0",
",",
"len",
"(",
"s",
".",
"Set",
")",
"-",
"1",
"\n",
"for",
"min",
"<",
"max",
"{",
"if",
"mid",
":=",
"(",
"min",
"+",
"max",
")",
">>",
"1",
";",
"s",
".",
"Set",
"[",
"mid",
"]",
".",
"Less",
"(",
"q",
")",
"{",
"min",
"=",
"mid",
"+",
"1",
"\n",
"}",
"else",
"{",
"max",
"=",
"mid",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"max",
"<",
"0",
"||",
"s",
".",
"Set",
"[",
"min",
"]",
".",
"Less",
"(",
"q",
")",
"{",
"return",
"len",
"(",
"s",
".",
"Set",
")",
",",
"false",
"// q is the new largest value",
"\n",
"}",
"\n",
"return",
"min",
",",
"s",
".",
"Set",
"[",
"min",
"]",
".",
"Contains",
"(",
"q",
")",
"\n",
"}"
]
| // search attempts to find the index of the sequence set value that contains q.
// If no values contain q, the returned index is the position where q should be
// inserted and ok is set to false. | [
"search",
"attempts",
"to",
"find",
"the",
"index",
"of",
"the",
"sequence",
"set",
"value",
"that",
"contains",
"q",
".",
"If",
"no",
"values",
"contain",
"q",
"the",
"returned",
"index",
"is",
"the",
"position",
"where",
"q",
"should",
"be",
"inserted",
"and",
"ok",
"is",
"set",
"to",
"false",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L276-L289 |
148,169 | emersion/go-imap | status.go | Err | func (r *StatusResp) Err() error {
if r == nil {
// No status response, connection closed before we get one
return errors.New("imap: connection closed during command execution")
}
if r.Type == StatusRespNo || r.Type == StatusRespBad {
return errors.New(r.Info)
}
return nil
} | go | func (r *StatusResp) Err() error {
if r == nil {
// No status response, connection closed before we get one
return errors.New("imap: connection closed during command execution")
}
if r.Type == StatusRespNo || r.Type == StatusRespBad {
return errors.New(r.Info)
}
return nil
} | [
"func",
"(",
"r",
"*",
"StatusResp",
")",
"Err",
"(",
")",
"error",
"{",
"if",
"r",
"==",
"nil",
"{",
"// No status response, connection closed before we get one",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"Type",
"==",
"StatusRespNo",
"||",
"r",
".",
"Type",
"==",
"StatusRespBad",
"{",
"return",
"errors",
".",
"New",
"(",
"r",
".",
"Info",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // If this status is NO or BAD, returns an error with the status info.
// Otherwise, returns nil. | [
"If",
"this",
"status",
"is",
"NO",
"or",
"BAD",
"returns",
"an",
"error",
"with",
"the",
"status",
"info",
".",
"Otherwise",
"returns",
"nil",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/status.go#L79-L89 |
148,170 | emersion/go-imap | utf7/encoder.go | encode | func encode(s []byte) []byte {
// len(s) is sufficient for UTF-8 to UTF-16 conversion if there are no
// control code points (see table below).
b := make([]byte, 0, len(s)+4)
for len(s) > 0 {
r, size := utf8.DecodeRune(s)
if r > utf8.MaxRune {
r, size = utf8.RuneError, 1 // Bug fix (issue 3785)
}
s = s[size:]
if r1, r2 := utf16.EncodeRune(r); r1 != repl {
b = append(b, byte(r1>>8), byte(r1))
r = r2
}
b = append(b, byte(r>>8), byte(r))
}
// Encode as base64
n := b64Enc.EncodedLen(len(b)) + 2
b64 := make([]byte, n)
b64Enc.Encode(b64[1:], b)
// Strip padding
n -= 2 - (len(b)+2)%3
b64 = b64[:n]
// Add UTF-7 shifts
b64[0] = '&'
b64[n-1] = '-'
return b64
} | go | func encode(s []byte) []byte {
// len(s) is sufficient for UTF-8 to UTF-16 conversion if there are no
// control code points (see table below).
b := make([]byte, 0, len(s)+4)
for len(s) > 0 {
r, size := utf8.DecodeRune(s)
if r > utf8.MaxRune {
r, size = utf8.RuneError, 1 // Bug fix (issue 3785)
}
s = s[size:]
if r1, r2 := utf16.EncodeRune(r); r1 != repl {
b = append(b, byte(r1>>8), byte(r1))
r = r2
}
b = append(b, byte(r>>8), byte(r))
}
// Encode as base64
n := b64Enc.EncodedLen(len(b)) + 2
b64 := make([]byte, n)
b64Enc.Encode(b64[1:], b)
// Strip padding
n -= 2 - (len(b)+2)%3
b64 = b64[:n]
// Add UTF-7 shifts
b64[0] = '&'
b64[n-1] = '-'
return b64
} | [
"func",
"encode",
"(",
"s",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"// len(s) is sufficient for UTF-8 to UTF-16 conversion if there are no",
"// control code points (see table below).",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"len",
"(",
"s",
")",
"+",
"4",
")",
"\n",
"for",
"len",
"(",
"s",
")",
">",
"0",
"{",
"r",
",",
"size",
":=",
"utf8",
".",
"DecodeRune",
"(",
"s",
")",
"\n",
"if",
"r",
">",
"utf8",
".",
"MaxRune",
"{",
"r",
",",
"size",
"=",
"utf8",
".",
"RuneError",
",",
"1",
"// Bug fix (issue 3785)",
"\n",
"}",
"\n",
"s",
"=",
"s",
"[",
"size",
":",
"]",
"\n",
"if",
"r1",
",",
"r2",
":=",
"utf16",
".",
"EncodeRune",
"(",
"r",
")",
";",
"r1",
"!=",
"repl",
"{",
"b",
"=",
"append",
"(",
"b",
",",
"byte",
"(",
"r1",
">>",
"8",
")",
",",
"byte",
"(",
"r1",
")",
")",
"\n",
"r",
"=",
"r2",
"\n",
"}",
"\n",
"b",
"=",
"append",
"(",
"b",
",",
"byte",
"(",
"r",
">>",
"8",
")",
",",
"byte",
"(",
"r",
")",
")",
"\n",
"}",
"\n\n",
"// Encode as base64",
"n",
":=",
"b64Enc",
".",
"EncodedLen",
"(",
"len",
"(",
"b",
")",
")",
"+",
"2",
"\n",
"b64",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"n",
")",
"\n",
"b64Enc",
".",
"Encode",
"(",
"b64",
"[",
"1",
":",
"]",
",",
"b",
")",
"\n\n",
"// Strip padding",
"n",
"-=",
"2",
"-",
"(",
"len",
"(",
"b",
")",
"+",
"2",
")",
"%",
"3",
"\n",
"b64",
"=",
"b64",
"[",
":",
"n",
"]",
"\n\n",
"// Add UTF-7 shifts",
"b64",
"[",
"0",
"]",
"=",
"'&'",
"\n",
"b64",
"[",
"n",
"-",
"1",
"]",
"=",
"'-'",
"\n",
"return",
"b64",
"\n",
"}"
]
| // Converts string s from UTF-8 to UTF-16-BE, encodes the result as base64,
// removes the padding, and adds UTF-7 shifts. | [
"Converts",
"string",
"s",
"from",
"UTF",
"-",
"8",
"to",
"UTF",
"-",
"16",
"-",
"BE",
"encodes",
"the",
"result",
"as",
"base64",
"removes",
"the",
"padding",
"and",
"adds",
"UTF",
"-",
"7",
"shifts",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/utf7/encoder.go#L61-L91 |
148,171 | emersion/go-imap | response.go | ReadResp | func ReadResp(r *Reader) (Resp, error) {
atom, err := r.ReadAtom()
if err != nil {
return nil, err
}
tag, ok := atom.(string)
if !ok {
return nil, newParseError("response tag is not an atom")
}
if tag == "+" {
if err := r.ReadSp(); err != nil {
r.UnreadRune()
}
resp := &ContinuationReq{}
resp.Info, err = r.ReadInfo()
if err != nil {
return nil, err
}
return resp, nil
}
if err := r.ReadSp(); err != nil {
return nil, err
}
// Can be either data or status
// Try to parse a status
var fields []interface{}
if atom, err := r.ReadAtom(); err == nil {
fields = append(fields, atom)
if err := r.ReadSp(); err == nil {
if name, ok := atom.(string); ok {
status := StatusRespType(name)
switch status {
case StatusRespOk, StatusRespNo, StatusRespBad, StatusRespPreauth, StatusRespBye:
resp := &StatusResp{
Tag: tag,
Type: status,
}
char, _, err := r.ReadRune()
if err != nil {
return nil, err
}
r.UnreadRune()
if char == '[' {
// Contains code & arguments
resp.Code, resp.Arguments, err = r.ReadRespCode()
if err != nil {
return nil, err
}
}
resp.Info, err = r.ReadInfo()
if err != nil {
return nil, err
}
return resp, nil
}
}
} else {
r.UnreadRune()
}
} else {
r.UnreadRune()
}
// Not a status so it's data
resp := &DataResp{Tag: tag}
var remaining []interface{}
remaining, err = r.ReadLine()
if err != nil {
return nil, err
}
resp.Fields = append(fields, remaining...)
return resp, nil
} | go | func ReadResp(r *Reader) (Resp, error) {
atom, err := r.ReadAtom()
if err != nil {
return nil, err
}
tag, ok := atom.(string)
if !ok {
return nil, newParseError("response tag is not an atom")
}
if tag == "+" {
if err := r.ReadSp(); err != nil {
r.UnreadRune()
}
resp := &ContinuationReq{}
resp.Info, err = r.ReadInfo()
if err != nil {
return nil, err
}
return resp, nil
}
if err := r.ReadSp(); err != nil {
return nil, err
}
// Can be either data or status
// Try to parse a status
var fields []interface{}
if atom, err := r.ReadAtom(); err == nil {
fields = append(fields, atom)
if err := r.ReadSp(); err == nil {
if name, ok := atom.(string); ok {
status := StatusRespType(name)
switch status {
case StatusRespOk, StatusRespNo, StatusRespBad, StatusRespPreauth, StatusRespBye:
resp := &StatusResp{
Tag: tag,
Type: status,
}
char, _, err := r.ReadRune()
if err != nil {
return nil, err
}
r.UnreadRune()
if char == '[' {
// Contains code & arguments
resp.Code, resp.Arguments, err = r.ReadRespCode()
if err != nil {
return nil, err
}
}
resp.Info, err = r.ReadInfo()
if err != nil {
return nil, err
}
return resp, nil
}
}
} else {
r.UnreadRune()
}
} else {
r.UnreadRune()
}
// Not a status so it's data
resp := &DataResp{Tag: tag}
var remaining []interface{}
remaining, err = r.ReadLine()
if err != nil {
return nil, err
}
resp.Fields = append(fields, remaining...)
return resp, nil
} | [
"func",
"ReadResp",
"(",
"r",
"*",
"Reader",
")",
"(",
"Resp",
",",
"error",
")",
"{",
"atom",
",",
"err",
":=",
"r",
".",
"ReadAtom",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tag",
",",
"ok",
":=",
"atom",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"newParseError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"tag",
"==",
"\"",
"\"",
"{",
"if",
"err",
":=",
"r",
".",
"ReadSp",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"r",
".",
"UnreadRune",
"(",
")",
"\n",
"}",
"\n\n",
"resp",
":=",
"&",
"ContinuationReq",
"{",
"}",
"\n",
"resp",
".",
"Info",
",",
"err",
"=",
"r",
".",
"ReadInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"resp",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"r",
".",
"ReadSp",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Can be either data or status",
"// Try to parse a status",
"var",
"fields",
"[",
"]",
"interface",
"{",
"}",
"\n",
"if",
"atom",
",",
"err",
":=",
"r",
".",
"ReadAtom",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"fields",
"=",
"append",
"(",
"fields",
",",
"atom",
")",
"\n\n",
"if",
"err",
":=",
"r",
".",
"ReadSp",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"if",
"name",
",",
"ok",
":=",
"atom",
".",
"(",
"string",
")",
";",
"ok",
"{",
"status",
":=",
"StatusRespType",
"(",
"name",
")",
"\n",
"switch",
"status",
"{",
"case",
"StatusRespOk",
",",
"StatusRespNo",
",",
"StatusRespBad",
",",
"StatusRespPreauth",
",",
"StatusRespBye",
":",
"resp",
":=",
"&",
"StatusResp",
"{",
"Tag",
":",
"tag",
",",
"Type",
":",
"status",
",",
"}",
"\n\n",
"char",
",",
"_",
",",
"err",
":=",
"r",
".",
"ReadRune",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"r",
".",
"UnreadRune",
"(",
")",
"\n\n",
"if",
"char",
"==",
"'['",
"{",
"// Contains code & arguments",
"resp",
".",
"Code",
",",
"resp",
".",
"Arguments",
",",
"err",
"=",
"r",
".",
"ReadRespCode",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"resp",
".",
"Info",
",",
"err",
"=",
"r",
".",
"ReadInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"resp",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"{",
"r",
".",
"UnreadRune",
"(",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"r",
".",
"UnreadRune",
"(",
")",
"\n",
"}",
"\n\n",
"// Not a status so it's data",
"resp",
":=",
"&",
"DataResp",
"{",
"Tag",
":",
"tag",
"}",
"\n\n",
"var",
"remaining",
"[",
"]",
"interface",
"{",
"}",
"\n",
"remaining",
",",
"err",
"=",
"r",
".",
"ReadLine",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"resp",
".",
"Fields",
"=",
"append",
"(",
"fields",
",",
"remaining",
"...",
")",
"\n",
"return",
"resp",
",",
"nil",
"\n",
"}"
]
| // ReadResp reads a single response from a Reader. | [
"ReadResp",
"reads",
"a",
"single",
"response",
"from",
"a",
"Reader",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/response.go#L14-L98 |
148,172 | emersion/go-imap | response.go | ParseNamedResp | func ParseNamedResp(resp Resp) (name string, fields []interface{}, ok bool) {
data, ok := resp.(*DataResp)
if !ok || len(data.Fields) == 0 {
return
}
// Some responses (namely EXISTS and RECENT) are formatted like so:
// [num] [name] [...]
// Which is fucking stupid. But we handle that here by checking if the
// response name is a number and then rearranging it.
if len(data.Fields) > 1 {
name, ok := data.Fields[1].(string)
if ok {
if _, err := ParseNumber(data.Fields[0]); err == nil {
fields := []interface{}{data.Fields[0]}
fields = append(fields, data.Fields[2:]...)
return strings.ToUpper(name), fields, true
}
}
}
// IMAP commands are formatted like this:
// [name] [...]
name, ok = data.Fields[0].(string)
if !ok {
return
}
return strings.ToUpper(name), data.Fields[1:], true
} | go | func ParseNamedResp(resp Resp) (name string, fields []interface{}, ok bool) {
data, ok := resp.(*DataResp)
if !ok || len(data.Fields) == 0 {
return
}
// Some responses (namely EXISTS and RECENT) are formatted like so:
// [num] [name] [...]
// Which is fucking stupid. But we handle that here by checking if the
// response name is a number and then rearranging it.
if len(data.Fields) > 1 {
name, ok := data.Fields[1].(string)
if ok {
if _, err := ParseNumber(data.Fields[0]); err == nil {
fields := []interface{}{data.Fields[0]}
fields = append(fields, data.Fields[2:]...)
return strings.ToUpper(name), fields, true
}
}
}
// IMAP commands are formatted like this:
// [name] [...]
name, ok = data.Fields[0].(string)
if !ok {
return
}
return strings.ToUpper(name), data.Fields[1:], true
} | [
"func",
"ParseNamedResp",
"(",
"resp",
"Resp",
")",
"(",
"name",
"string",
",",
"fields",
"[",
"]",
"interface",
"{",
"}",
",",
"ok",
"bool",
")",
"{",
"data",
",",
"ok",
":=",
"resp",
".",
"(",
"*",
"DataResp",
")",
"\n",
"if",
"!",
"ok",
"||",
"len",
"(",
"data",
".",
"Fields",
")",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"// Some responses (namely EXISTS and RECENT) are formatted like so:",
"// [num] [name] [...]",
"// Which is fucking stupid. But we handle that here by checking if the",
"// response name is a number and then rearranging it.",
"if",
"len",
"(",
"data",
".",
"Fields",
")",
">",
"1",
"{",
"name",
",",
"ok",
":=",
"data",
".",
"Fields",
"[",
"1",
"]",
".",
"(",
"string",
")",
"\n",
"if",
"ok",
"{",
"if",
"_",
",",
"err",
":=",
"ParseNumber",
"(",
"data",
".",
"Fields",
"[",
"0",
"]",
")",
";",
"err",
"==",
"nil",
"{",
"fields",
":=",
"[",
"]",
"interface",
"{",
"}",
"{",
"data",
".",
"Fields",
"[",
"0",
"]",
"}",
"\n",
"fields",
"=",
"append",
"(",
"fields",
",",
"data",
".",
"Fields",
"[",
"2",
":",
"]",
"...",
")",
"\n",
"return",
"strings",
".",
"ToUpper",
"(",
"name",
")",
",",
"fields",
",",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// IMAP commands are formatted like this:",
"// [name] [...]",
"name",
",",
"ok",
"=",
"data",
".",
"Fields",
"[",
"0",
"]",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n",
"return",
"strings",
".",
"ToUpper",
"(",
"name",
")",
",",
"data",
".",
"Fields",
"[",
"1",
":",
"]",
",",
"true",
"\n",
"}"
]
| // ParseNamedResp attempts to parse a named data response. | [
"ParseNamedResp",
"attempts",
"to",
"parse",
"a",
"named",
"data",
"response",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/response.go#L153-L181 |
148,173 | emersion/go-imap | command.go | Parse | func (cmd *Command) Parse(fields []interface{}) error {
if len(fields) < 2 {
return errors.New("imap: cannot parse command: no enough fields")
}
var ok bool
if cmd.Tag, ok = fields[0].(string); !ok {
return errors.New("imap: cannot parse command: invalid tag")
}
if cmd.Name, ok = fields[1].(string); !ok {
return errors.New("imap: cannot parse command: invalid name")
}
cmd.Name = strings.ToUpper(cmd.Name) // Command names are case-insensitive
cmd.Arguments = fields[2:]
return nil
} | go | func (cmd *Command) Parse(fields []interface{}) error {
if len(fields) < 2 {
return errors.New("imap: cannot parse command: no enough fields")
}
var ok bool
if cmd.Tag, ok = fields[0].(string); !ok {
return errors.New("imap: cannot parse command: invalid tag")
}
if cmd.Name, ok = fields[1].(string); !ok {
return errors.New("imap: cannot parse command: invalid name")
}
cmd.Name = strings.ToUpper(cmd.Name) // Command names are case-insensitive
cmd.Arguments = fields[2:]
return nil
} | [
"func",
"(",
"cmd",
"*",
"Command",
")",
"Parse",
"(",
"fields",
"[",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"len",
"(",
"fields",
")",
"<",
"2",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"ok",
"bool",
"\n",
"if",
"cmd",
".",
"Tag",
",",
"ok",
"=",
"fields",
"[",
"0",
"]",
".",
"(",
"string",
")",
";",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"cmd",
".",
"Name",
",",
"ok",
"=",
"fields",
"[",
"1",
"]",
".",
"(",
"string",
")",
";",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"cmd",
".",
"Name",
"=",
"strings",
".",
"ToUpper",
"(",
"cmd",
".",
"Name",
")",
"// Command names are case-insensitive",
"\n\n",
"cmd",
".",
"Arguments",
"=",
"fields",
"[",
"2",
":",
"]",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Parse a command from fields. | [
"Parse",
"a",
"command",
"from",
"fields",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/command.go#L41-L57 |
148,174 | emersion/go-imap | client/cmd_auth.go | Select | func (c *Client) Select(name string, readOnly bool) (*imap.MailboxStatus, error) {
if err := c.ensureAuthenticated(); err != nil {
return nil, err
}
cmd := &commands.Select{
Mailbox: name,
ReadOnly: readOnly,
}
mbox := &imap.MailboxStatus{Name: name, Items: make(map[imap.StatusItem]interface{})}
res := &responses.Select{
Mailbox: mbox,
}
c.locker.Lock()
c.mailbox = mbox
c.locker.Unlock()
status, err := c.execute(cmd, res)
if err != nil {
c.locker.Lock()
c.mailbox = nil
c.locker.Unlock()
return nil, err
}
if err := status.Err(); err != nil {
c.locker.Lock()
c.mailbox = nil
c.locker.Unlock()
return nil, err
}
c.locker.Lock()
mbox.ReadOnly = (status.Code == imap.CodeReadOnly)
c.state = imap.SelectedState
c.locker.Unlock()
return mbox, nil
} | go | func (c *Client) Select(name string, readOnly bool) (*imap.MailboxStatus, error) {
if err := c.ensureAuthenticated(); err != nil {
return nil, err
}
cmd := &commands.Select{
Mailbox: name,
ReadOnly: readOnly,
}
mbox := &imap.MailboxStatus{Name: name, Items: make(map[imap.StatusItem]interface{})}
res := &responses.Select{
Mailbox: mbox,
}
c.locker.Lock()
c.mailbox = mbox
c.locker.Unlock()
status, err := c.execute(cmd, res)
if err != nil {
c.locker.Lock()
c.mailbox = nil
c.locker.Unlock()
return nil, err
}
if err := status.Err(); err != nil {
c.locker.Lock()
c.mailbox = nil
c.locker.Unlock()
return nil, err
}
c.locker.Lock()
mbox.ReadOnly = (status.Code == imap.CodeReadOnly)
c.state = imap.SelectedState
c.locker.Unlock()
return mbox, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Select",
"(",
"name",
"string",
",",
"readOnly",
"bool",
")",
"(",
"*",
"imap",
".",
"MailboxStatus",
",",
"error",
")",
"{",
"if",
"err",
":=",
"c",
".",
"ensureAuthenticated",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"cmd",
":=",
"&",
"commands",
".",
"Select",
"{",
"Mailbox",
":",
"name",
",",
"ReadOnly",
":",
"readOnly",
",",
"}",
"\n\n",
"mbox",
":=",
"&",
"imap",
".",
"MailboxStatus",
"{",
"Name",
":",
"name",
",",
"Items",
":",
"make",
"(",
"map",
"[",
"imap",
".",
"StatusItem",
"]",
"interface",
"{",
"}",
")",
"}",
"\n",
"res",
":=",
"&",
"responses",
".",
"Select",
"{",
"Mailbox",
":",
"mbox",
",",
"}",
"\n",
"c",
".",
"locker",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"mailbox",
"=",
"mbox",
"\n",
"c",
".",
"locker",
".",
"Unlock",
"(",
")",
"\n\n",
"status",
",",
"err",
":=",
"c",
".",
"execute",
"(",
"cmd",
",",
"res",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"locker",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"mailbox",
"=",
"nil",
"\n",
"c",
".",
"locker",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"status",
".",
"Err",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"locker",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"mailbox",
"=",
"nil",
"\n",
"c",
".",
"locker",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"c",
".",
"locker",
".",
"Lock",
"(",
")",
"\n",
"mbox",
".",
"ReadOnly",
"=",
"(",
"status",
".",
"Code",
"==",
"imap",
".",
"CodeReadOnly",
")",
"\n",
"c",
".",
"state",
"=",
"imap",
".",
"SelectedState",
"\n",
"c",
".",
"locker",
".",
"Unlock",
"(",
")",
"\n",
"return",
"mbox",
",",
"nil",
"\n",
"}"
]
| // Select selects a mailbox so that messages in the mailbox can be accessed. Any
// currently selected mailbox is deselected before attempting the new selection.
// Even if the readOnly parameter is set to false, the server can decide to open
// the mailbox in read-only mode. | [
"Select",
"selects",
"a",
"mailbox",
"so",
"that",
"messages",
"in",
"the",
"mailbox",
"can",
"be",
"accessed",
".",
"Any",
"currently",
"selected",
"mailbox",
"is",
"deselected",
"before",
"attempting",
"the",
"new",
"selection",
".",
"Even",
"if",
"the",
"readOnly",
"parameter",
"is",
"set",
"to",
"false",
"the",
"server",
"can",
"decide",
"to",
"open",
"the",
"mailbox",
"in",
"read",
"-",
"only",
"mode",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_auth.go#L28-L65 |
148,175 | emersion/go-imap | client/cmd_auth.go | Rename | func (c *Client) Rename(existingName, newName string) error {
if err := c.ensureAuthenticated(); err != nil {
return err
}
cmd := &commands.Rename{
Existing: existingName,
New: newName,
}
status, err := c.execute(cmd, nil)
if err != nil {
return err
}
return status.Err()
} | go | func (c *Client) Rename(existingName, newName string) error {
if err := c.ensureAuthenticated(); err != nil {
return err
}
cmd := &commands.Rename{
Existing: existingName,
New: newName,
}
status, err := c.execute(cmd, nil)
if err != nil {
return err
}
return status.Err()
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Rename",
"(",
"existingName",
",",
"newName",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"c",
".",
"ensureAuthenticated",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"cmd",
":=",
"&",
"commands",
".",
"Rename",
"{",
"Existing",
":",
"existingName",
",",
"New",
":",
"newName",
",",
"}",
"\n\n",
"status",
",",
"err",
":=",
"c",
".",
"execute",
"(",
"cmd",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"status",
".",
"Err",
"(",
")",
"\n",
"}"
]
| // Rename changes the name of a mailbox. | [
"Rename",
"changes",
"the",
"name",
"of",
"a",
"mailbox",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_auth.go#L102-L117 |
148,176 | emersion/go-imap | client/cmd_auth.go | Subscribe | func (c *Client) Subscribe(name string) error {
if err := c.ensureAuthenticated(); err != nil {
return err
}
cmd := &commands.Subscribe{
Mailbox: name,
}
status, err := c.execute(cmd, nil)
if err != nil {
return err
}
return status.Err()
} | go | func (c *Client) Subscribe(name string) error {
if err := c.ensureAuthenticated(); err != nil {
return err
}
cmd := &commands.Subscribe{
Mailbox: name,
}
status, err := c.execute(cmd, nil)
if err != nil {
return err
}
return status.Err()
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Subscribe",
"(",
"name",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"c",
".",
"ensureAuthenticated",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"cmd",
":=",
"&",
"commands",
".",
"Subscribe",
"{",
"Mailbox",
":",
"name",
",",
"}",
"\n\n",
"status",
",",
"err",
":=",
"c",
".",
"execute",
"(",
"cmd",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"status",
".",
"Err",
"(",
")",
"\n",
"}"
]
| // Subscribe adds the specified mailbox name to the server's set of "active" or
// "subscribed" mailboxes. | [
"Subscribe",
"adds",
"the",
"specified",
"mailbox",
"name",
"to",
"the",
"server",
"s",
"set",
"of",
"active",
"or",
"subscribed",
"mailboxes",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_auth.go#L121-L135 |
148,177 | emersion/go-imap | client/cmd_auth.go | Status | func (c *Client) Status(name string, items []imap.StatusItem) (*imap.MailboxStatus, error) {
if err := c.ensureAuthenticated(); err != nil {
return nil, err
}
cmd := &commands.Status{
Mailbox: name,
Items: items,
}
res := &responses.Status{
Mailbox: new(imap.MailboxStatus),
}
status, err := c.execute(cmd, res)
if err != nil {
return nil, err
}
return res.Mailbox, status.Err()
} | go | func (c *Client) Status(name string, items []imap.StatusItem) (*imap.MailboxStatus, error) {
if err := c.ensureAuthenticated(); err != nil {
return nil, err
}
cmd := &commands.Status{
Mailbox: name,
Items: items,
}
res := &responses.Status{
Mailbox: new(imap.MailboxStatus),
}
status, err := c.execute(cmd, res)
if err != nil {
return nil, err
}
return res.Mailbox, status.Err()
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Status",
"(",
"name",
"string",
",",
"items",
"[",
"]",
"imap",
".",
"StatusItem",
")",
"(",
"*",
"imap",
".",
"MailboxStatus",
",",
"error",
")",
"{",
"if",
"err",
":=",
"c",
".",
"ensureAuthenticated",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"cmd",
":=",
"&",
"commands",
".",
"Status",
"{",
"Mailbox",
":",
"name",
",",
"Items",
":",
"items",
",",
"}",
"\n",
"res",
":=",
"&",
"responses",
".",
"Status",
"{",
"Mailbox",
":",
"new",
"(",
"imap",
".",
"MailboxStatus",
")",
",",
"}",
"\n\n",
"status",
",",
"err",
":=",
"c",
".",
"execute",
"(",
"cmd",
",",
"res",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"res",
".",
"Mailbox",
",",
"status",
".",
"Err",
"(",
")",
"\n",
"}"
]
| // Status requests the status of the indicated mailbox. It does not change the
// currently selected mailbox, nor does it affect the state of any messages in
// the queried mailbox.
//
// See RFC 3501 section 6.3.10 for a list of items that can be requested. | [
"Status",
"requests",
"the",
"status",
"of",
"the",
"indicated",
"mailbox",
".",
"It",
"does",
"not",
"change",
"the",
"currently",
"selected",
"mailbox",
"nor",
"does",
"it",
"affect",
"the",
"state",
"of",
"any",
"messages",
"in",
"the",
"queried",
"mailbox",
".",
"See",
"RFC",
"3501",
"section",
"6",
".",
"3",
".",
"10",
"for",
"a",
"list",
"of",
"items",
"that",
"can",
"be",
"requested",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_auth.go#L213-L231 |
148,178 | emersion/go-imap | client/cmd_auth.go | Append | func (c *Client) Append(mbox string, flags []string, date time.Time, msg imap.Literal) error {
if err := c.ensureAuthenticated(); err != nil {
return err
}
cmd := &commands.Append{
Mailbox: mbox,
Flags: flags,
Date: date,
Message: msg,
}
status, err := c.execute(cmd, nil)
if err != nil {
return err
}
return status.Err()
} | go | func (c *Client) Append(mbox string, flags []string, date time.Time, msg imap.Literal) error {
if err := c.ensureAuthenticated(); err != nil {
return err
}
cmd := &commands.Append{
Mailbox: mbox,
Flags: flags,
Date: date,
Message: msg,
}
status, err := c.execute(cmd, nil)
if err != nil {
return err
}
return status.Err()
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Append",
"(",
"mbox",
"string",
",",
"flags",
"[",
"]",
"string",
",",
"date",
"time",
".",
"Time",
",",
"msg",
"imap",
".",
"Literal",
")",
"error",
"{",
"if",
"err",
":=",
"c",
".",
"ensureAuthenticated",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"cmd",
":=",
"&",
"commands",
".",
"Append",
"{",
"Mailbox",
":",
"mbox",
",",
"Flags",
":",
"flags",
",",
"Date",
":",
"date",
",",
"Message",
":",
"msg",
",",
"}",
"\n\n",
"status",
",",
"err",
":=",
"c",
".",
"execute",
"(",
"cmd",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"status",
".",
"Err",
"(",
")",
"\n",
"}"
]
| // Append appends the literal argument as a new message to the end of the
// specified destination mailbox. This argument SHOULD be in the format of an
// RFC 2822 message. flags and date are optional arguments and can be set to
// nil. | [
"Append",
"appends",
"the",
"literal",
"argument",
"as",
"a",
"new",
"message",
"to",
"the",
"end",
"of",
"the",
"specified",
"destination",
"mailbox",
".",
"This",
"argument",
"SHOULD",
"be",
"in",
"the",
"format",
"of",
"an",
"RFC",
"2822",
"message",
".",
"flags",
"and",
"date",
"are",
"optional",
"arguments",
"and",
"can",
"be",
"set",
"to",
"nil",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_auth.go#L237-L254 |
148,179 | emersion/go-imap | backend/backendutil/search.go | MatchFlags | func MatchFlags(flags []string, c *imap.SearchCriteria) bool {
flagsMap := make(map[string]bool)
for _, f := range flags {
flagsMap[f] = true
}
return matchFlags(flagsMap, c)
} | go | func MatchFlags(flags []string, c *imap.SearchCriteria) bool {
flagsMap := make(map[string]bool)
for _, f := range flags {
flagsMap[f] = true
}
return matchFlags(flagsMap, c)
} | [
"func",
"MatchFlags",
"(",
"flags",
"[",
"]",
"string",
",",
"c",
"*",
"imap",
".",
"SearchCriteria",
")",
"bool",
"{",
"flagsMap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"flags",
"{",
"flagsMap",
"[",
"f",
"]",
"=",
"true",
"\n",
"}",
"\n\n",
"return",
"matchFlags",
"(",
"flagsMap",
",",
"c",
")",
"\n",
"}"
]
| // MatchFlags returns true if a flag list matches the provided criteria. | [
"MatchFlags",
"returns",
"true",
"if",
"a",
"flag",
"list",
"matches",
"the",
"provided",
"criteria",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/backend/backendutil/search.go#L172-L179 |
148,180 | emersion/go-imap | backend/backendutil/search.go | MatchSeqNumAndUid | func MatchSeqNumAndUid(seqNum uint32, uid uint32, c *imap.SearchCriteria) bool {
if c.SeqNum != nil && !c.SeqNum.Contains(seqNum) {
return false
}
if c.Uid != nil && !c.Uid.Contains(uid) {
return false
}
for _, not := range c.Not {
if MatchSeqNumAndUid(seqNum, uid, not) {
return false
}
}
for _, or := range c.Or {
if !MatchSeqNumAndUid(seqNum, uid, or[0]) && !MatchSeqNumAndUid(seqNum, uid, or[1]) {
return false
}
}
return true
} | go | func MatchSeqNumAndUid(seqNum uint32, uid uint32, c *imap.SearchCriteria) bool {
if c.SeqNum != nil && !c.SeqNum.Contains(seqNum) {
return false
}
if c.Uid != nil && !c.Uid.Contains(uid) {
return false
}
for _, not := range c.Not {
if MatchSeqNumAndUid(seqNum, uid, not) {
return false
}
}
for _, or := range c.Or {
if !MatchSeqNumAndUid(seqNum, uid, or[0]) && !MatchSeqNumAndUid(seqNum, uid, or[1]) {
return false
}
}
return true
} | [
"func",
"MatchSeqNumAndUid",
"(",
"seqNum",
"uint32",
",",
"uid",
"uint32",
",",
"c",
"*",
"imap",
".",
"SearchCriteria",
")",
"bool",
"{",
"if",
"c",
".",
"SeqNum",
"!=",
"nil",
"&&",
"!",
"c",
".",
"SeqNum",
".",
"Contains",
"(",
"seqNum",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"c",
".",
"Uid",
"!=",
"nil",
"&&",
"!",
"c",
".",
"Uid",
".",
"Contains",
"(",
"uid",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"not",
":=",
"range",
"c",
".",
"Not",
"{",
"if",
"MatchSeqNumAndUid",
"(",
"seqNum",
",",
"uid",
",",
"not",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"or",
":=",
"range",
"c",
".",
"Or",
"{",
"if",
"!",
"MatchSeqNumAndUid",
"(",
"seqNum",
",",
"uid",
",",
"or",
"[",
"0",
"]",
")",
"&&",
"!",
"MatchSeqNumAndUid",
"(",
"seqNum",
",",
"uid",
",",
"or",
"[",
"1",
"]",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
]
| // MatchSeqNumAndUid returns true if a sequence number and a UID matches the
// provided criteria. | [
"MatchSeqNumAndUid",
"returns",
"true",
"if",
"a",
"sequence",
"number",
"and",
"a",
"UID",
"matches",
"the",
"provided",
"criteria",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/backend/backendutil/search.go#L183-L202 |
148,181 | emersion/go-imap | backend/backendutil/search.go | MatchDate | func MatchDate(date time.Time, c *imap.SearchCriteria) bool {
date = date.Round(24 * time.Hour)
if !c.Since.IsZero() && !date.After(c.Since) {
return false
}
if !c.Before.IsZero() && !date.Before(c.Before) {
return false
}
for _, not := range c.Not {
if MatchDate(date, not) {
return false
}
}
for _, or := range c.Or {
if !MatchDate(date, or[0]) && !MatchDate(date, or[1]) {
return false
}
}
return true
} | go | func MatchDate(date time.Time, c *imap.SearchCriteria) bool {
date = date.Round(24 * time.Hour)
if !c.Since.IsZero() && !date.After(c.Since) {
return false
}
if !c.Before.IsZero() && !date.Before(c.Before) {
return false
}
for _, not := range c.Not {
if MatchDate(date, not) {
return false
}
}
for _, or := range c.Or {
if !MatchDate(date, or[0]) && !MatchDate(date, or[1]) {
return false
}
}
return true
} | [
"func",
"MatchDate",
"(",
"date",
"time",
".",
"Time",
",",
"c",
"*",
"imap",
".",
"SearchCriteria",
")",
"bool",
"{",
"date",
"=",
"date",
".",
"Round",
"(",
"24",
"*",
"time",
".",
"Hour",
")",
"\n",
"if",
"!",
"c",
".",
"Since",
".",
"IsZero",
"(",
")",
"&&",
"!",
"date",
".",
"After",
"(",
"c",
".",
"Since",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"c",
".",
"Before",
".",
"IsZero",
"(",
")",
"&&",
"!",
"date",
".",
"Before",
"(",
"c",
".",
"Before",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"not",
":=",
"range",
"c",
".",
"Not",
"{",
"if",
"MatchDate",
"(",
"date",
",",
"not",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"or",
":=",
"range",
"c",
".",
"Or",
"{",
"if",
"!",
"MatchDate",
"(",
"date",
",",
"or",
"[",
"0",
"]",
")",
"&&",
"!",
"MatchDate",
"(",
"date",
",",
"or",
"[",
"1",
"]",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
]
| // MatchDate returns true if a date matches the provided criteria. | [
"MatchDate",
"returns",
"true",
"if",
"a",
"date",
"matches",
"the",
"provided",
"criteria",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/backend/backendutil/search.go#L205-L225 |
148,182 | emersion/go-imap | client/cmd_noauth.go | StartTLS | func (c *Client) StartTLS(tlsConfig *tls.Config) error {
if c.isTLS {
return ErrTLSAlreadyEnabled
}
cmd := new(commands.StartTLS)
err := c.Upgrade(func(conn net.Conn) (net.Conn, error) {
// Flag connection as in upgrading
c.upgrading = true
if status, err := c.execute(cmd, nil); err != nil {
return nil, err
} else if err := status.Err(); err != nil {
return nil, err
}
// Wait for reader to block.
c.conn.WaitReady()
tlsConn := tls.Client(conn, tlsConfig)
if err := tlsConn.Handshake(); err != nil {
return nil, err
}
// Capabilities change when TLS is enabled
c.locker.Lock()
c.caps = nil
c.locker.Unlock()
return tlsConn, nil
})
if err != nil {
return err
}
c.isTLS = true
return nil
} | go | func (c *Client) StartTLS(tlsConfig *tls.Config) error {
if c.isTLS {
return ErrTLSAlreadyEnabled
}
cmd := new(commands.StartTLS)
err := c.Upgrade(func(conn net.Conn) (net.Conn, error) {
// Flag connection as in upgrading
c.upgrading = true
if status, err := c.execute(cmd, nil); err != nil {
return nil, err
} else if err := status.Err(); err != nil {
return nil, err
}
// Wait for reader to block.
c.conn.WaitReady()
tlsConn := tls.Client(conn, tlsConfig)
if err := tlsConn.Handshake(); err != nil {
return nil, err
}
// Capabilities change when TLS is enabled
c.locker.Lock()
c.caps = nil
c.locker.Unlock()
return tlsConn, nil
})
if err != nil {
return err
}
c.isTLS = true
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"StartTLS",
"(",
"tlsConfig",
"*",
"tls",
".",
"Config",
")",
"error",
"{",
"if",
"c",
".",
"isTLS",
"{",
"return",
"ErrTLSAlreadyEnabled",
"\n",
"}",
"\n\n",
"cmd",
":=",
"new",
"(",
"commands",
".",
"StartTLS",
")",
"\n\n",
"err",
":=",
"c",
".",
"Upgrade",
"(",
"func",
"(",
"conn",
"net",
".",
"Conn",
")",
"(",
"net",
".",
"Conn",
",",
"error",
")",
"{",
"// Flag connection as in upgrading",
"c",
".",
"upgrading",
"=",
"true",
"\n",
"if",
"status",
",",
"err",
":=",
"c",
".",
"execute",
"(",
"cmd",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"if",
"err",
":=",
"status",
".",
"Err",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Wait for reader to block.",
"c",
".",
"conn",
".",
"WaitReady",
"(",
")",
"\n",
"tlsConn",
":=",
"tls",
".",
"Client",
"(",
"conn",
",",
"tlsConfig",
")",
"\n",
"if",
"err",
":=",
"tlsConn",
".",
"Handshake",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Capabilities change when TLS is enabled",
"c",
".",
"locker",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"caps",
"=",
"nil",
"\n",
"c",
".",
"locker",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"tlsConn",
",",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"c",
".",
"isTLS",
"=",
"true",
"\n",
"return",
"nil",
"\n",
"}"
]
| // StartTLS starts TLS negotiation. | [
"StartTLS",
"starts",
"TLS",
"negotiation",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_noauth.go#L33-L69 |
148,183 | emersion/go-imap | client/cmd_noauth.go | SupportAuth | func (c *Client) SupportAuth(mech string) (bool, error) {
return c.Support("AUTH=" + mech)
} | go | func (c *Client) SupportAuth(mech string) (bool, error) {
return c.Support("AUTH=" + mech)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SupportAuth",
"(",
"mech",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"return",
"c",
".",
"Support",
"(",
"\"",
"\"",
"+",
"mech",
")",
"\n",
"}"
]
| // SupportAuth checks if the server supports a given authentication mechanism. | [
"SupportAuth",
"checks",
"if",
"the",
"server",
"supports",
"a",
"given",
"authentication",
"mechanism",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_noauth.go#L72-L74 |
148,184 | emersion/go-imap | client/cmd_noauth.go | Authenticate | func (c *Client) Authenticate(auth sasl.Client) error {
if c.State() != imap.NotAuthenticatedState {
return ErrAlreadyLoggedIn
}
mech, ir, err := auth.Start()
if err != nil {
return err
}
cmd := &commands.Authenticate{
Mechanism: mech,
}
res := &responses.Authenticate{
Mechanism: auth,
InitialResponse: ir,
AuthReply: func(reply []byte) error {
c.replies <- reply
return nil
},
}
status, err := c.execute(cmd, res)
if err != nil {
return err
}
if err = status.Err(); err != nil {
return err
}
c.locker.Lock()
c.state = imap.AuthenticatedState
c.caps = nil // Capabilities change when user is logged in
c.locker.Unlock()
if status.Code == "CAPABILITY" {
c.gotStatusCaps(status.Arguments)
}
return nil
} | go | func (c *Client) Authenticate(auth sasl.Client) error {
if c.State() != imap.NotAuthenticatedState {
return ErrAlreadyLoggedIn
}
mech, ir, err := auth.Start()
if err != nil {
return err
}
cmd := &commands.Authenticate{
Mechanism: mech,
}
res := &responses.Authenticate{
Mechanism: auth,
InitialResponse: ir,
AuthReply: func(reply []byte) error {
c.replies <- reply
return nil
},
}
status, err := c.execute(cmd, res)
if err != nil {
return err
}
if err = status.Err(); err != nil {
return err
}
c.locker.Lock()
c.state = imap.AuthenticatedState
c.caps = nil // Capabilities change when user is logged in
c.locker.Unlock()
if status.Code == "CAPABILITY" {
c.gotStatusCaps(status.Arguments)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Authenticate",
"(",
"auth",
"sasl",
".",
"Client",
")",
"error",
"{",
"if",
"c",
".",
"State",
"(",
")",
"!=",
"imap",
".",
"NotAuthenticatedState",
"{",
"return",
"ErrAlreadyLoggedIn",
"\n",
"}",
"\n\n",
"mech",
",",
"ir",
",",
"err",
":=",
"auth",
".",
"Start",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"cmd",
":=",
"&",
"commands",
".",
"Authenticate",
"{",
"Mechanism",
":",
"mech",
",",
"}",
"\n\n",
"res",
":=",
"&",
"responses",
".",
"Authenticate",
"{",
"Mechanism",
":",
"auth",
",",
"InitialResponse",
":",
"ir",
",",
"AuthReply",
":",
"func",
"(",
"reply",
"[",
"]",
"byte",
")",
"error",
"{",
"c",
".",
"replies",
"<-",
"reply",
"\n",
"return",
"nil",
"\n",
"}",
",",
"}",
"\n\n",
"status",
",",
"err",
":=",
"c",
".",
"execute",
"(",
"cmd",
",",
"res",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
"=",
"status",
".",
"Err",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"c",
".",
"locker",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"state",
"=",
"imap",
".",
"AuthenticatedState",
"\n",
"c",
".",
"caps",
"=",
"nil",
"// Capabilities change when user is logged in",
"\n",
"c",
".",
"locker",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"status",
".",
"Code",
"==",
"\"",
"\"",
"{",
"c",
".",
"gotStatusCaps",
"(",
"status",
".",
"Arguments",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // Authenticate indicates a SASL authentication mechanism to the server. If the
// server supports the requested authentication mechanism, it performs an
// authentication protocol exchange to authenticate and identify the client. | [
"Authenticate",
"indicates",
"a",
"SASL",
"authentication",
"mechanism",
"to",
"the",
"server",
".",
"If",
"the",
"server",
"supports",
"the",
"requested",
"authentication",
"mechanism",
"it",
"performs",
"an",
"authentication",
"protocol",
"exchange",
"to",
"authenticate",
"and",
"identify",
"the",
"client",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_noauth.go#L79-L120 |
148,185 | emersion/go-imap | client/cmd_noauth.go | Login | func (c *Client) Login(username, password string) error {
if state := c.State(); state == imap.AuthenticatedState || state == imap.SelectedState {
return ErrAlreadyLoggedIn
}
c.locker.Lock()
loginDisabled := c.caps != nil && c.caps["LOGINDISABLED"]
c.locker.Unlock()
if loginDisabled {
return ErrLoginDisabled
}
cmd := &commands.Login{
Username: username,
Password: password,
}
status, err := c.execute(cmd, nil)
if err != nil {
return err
}
if err = status.Err(); err != nil {
return err
}
c.locker.Lock()
c.state = imap.AuthenticatedState
c.caps = nil // Capabilities change when user is logged in
c.locker.Unlock()
if status.Code == "CAPABILITY" {
c.gotStatusCaps(status.Arguments)
}
return nil
} | go | func (c *Client) Login(username, password string) error {
if state := c.State(); state == imap.AuthenticatedState || state == imap.SelectedState {
return ErrAlreadyLoggedIn
}
c.locker.Lock()
loginDisabled := c.caps != nil && c.caps["LOGINDISABLED"]
c.locker.Unlock()
if loginDisabled {
return ErrLoginDisabled
}
cmd := &commands.Login{
Username: username,
Password: password,
}
status, err := c.execute(cmd, nil)
if err != nil {
return err
}
if err = status.Err(); err != nil {
return err
}
c.locker.Lock()
c.state = imap.AuthenticatedState
c.caps = nil // Capabilities change when user is logged in
c.locker.Unlock()
if status.Code == "CAPABILITY" {
c.gotStatusCaps(status.Arguments)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Login",
"(",
"username",
",",
"password",
"string",
")",
"error",
"{",
"if",
"state",
":=",
"c",
".",
"State",
"(",
")",
";",
"state",
"==",
"imap",
".",
"AuthenticatedState",
"||",
"state",
"==",
"imap",
".",
"SelectedState",
"{",
"return",
"ErrAlreadyLoggedIn",
"\n",
"}",
"\n\n",
"c",
".",
"locker",
".",
"Lock",
"(",
")",
"\n",
"loginDisabled",
":=",
"c",
".",
"caps",
"!=",
"nil",
"&&",
"c",
".",
"caps",
"[",
"\"",
"\"",
"]",
"\n",
"c",
".",
"locker",
".",
"Unlock",
"(",
")",
"\n",
"if",
"loginDisabled",
"{",
"return",
"ErrLoginDisabled",
"\n",
"}",
"\n\n",
"cmd",
":=",
"&",
"commands",
".",
"Login",
"{",
"Username",
":",
"username",
",",
"Password",
":",
"password",
",",
"}",
"\n\n",
"status",
",",
"err",
":=",
"c",
".",
"execute",
"(",
"cmd",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
"=",
"status",
".",
"Err",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"c",
".",
"locker",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"state",
"=",
"imap",
".",
"AuthenticatedState",
"\n",
"c",
".",
"caps",
"=",
"nil",
"// Capabilities change when user is logged in",
"\n",
"c",
".",
"locker",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"status",
".",
"Code",
"==",
"\"",
"\"",
"{",
"c",
".",
"gotStatusCaps",
"(",
"status",
".",
"Arguments",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Login identifies the client to the server and carries the plaintext password
// authenticating this user. | [
"Login",
"identifies",
"the",
"client",
"to",
"the",
"server",
"and",
"carries",
"the",
"plaintext",
"password",
"authenticating",
"this",
"user",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_noauth.go#L124-L158 |
148,186 | emersion/go-imap | message.go | CanonicalFlag | func CanonicalFlag(flag string) string {
flag = strings.ToLower(flag)
for _, f := range flags {
if strings.ToLower(f) == flag {
return f
}
}
return flag
} | go | func CanonicalFlag(flag string) string {
flag = strings.ToLower(flag)
for _, f := range flags {
if strings.ToLower(f) == flag {
return f
}
}
return flag
} | [
"func",
"CanonicalFlag",
"(",
"flag",
"string",
")",
"string",
"{",
"flag",
"=",
"strings",
".",
"ToLower",
"(",
"flag",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"flags",
"{",
"if",
"strings",
".",
"ToLower",
"(",
"f",
")",
"==",
"flag",
"{",
"return",
"f",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"flag",
"\n",
"}"
]
| // CanonicalFlag returns the canonical form of a flag. Flags are case-insensitive.
//
// If the flag is defined in RFC 3501, it returns the flag with the case of the
// RFC. Otherwise, it returns the lowercase version of the flag. | [
"CanonicalFlag",
"returns",
"the",
"canonical",
"form",
"of",
"a",
"flag",
".",
"Flags",
"are",
"case",
"-",
"insensitive",
".",
"If",
"the",
"flag",
"is",
"defined",
"in",
"RFC",
"3501",
"it",
"returns",
"the",
"flag",
"with",
"the",
"case",
"of",
"the",
"RFC",
".",
"Otherwise",
"it",
"returns",
"the",
"lowercase",
"version",
"of",
"the",
"flag",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/message.go#L54-L62 |
148,187 | emersion/go-imap | message.go | NewMessage | func NewMessage(seqNum uint32, items []FetchItem) *Message {
msg := &Message{
SeqNum: seqNum,
Items: make(map[FetchItem]interface{}),
Body: make(map[*BodySectionName]Literal),
itemsOrder: items,
}
for _, k := range items {
msg.Items[k] = nil
}
return msg
} | go | func NewMessage(seqNum uint32, items []FetchItem) *Message {
msg := &Message{
SeqNum: seqNum,
Items: make(map[FetchItem]interface{}),
Body: make(map[*BodySectionName]Literal),
itemsOrder: items,
}
for _, k := range items {
msg.Items[k] = nil
}
return msg
} | [
"func",
"NewMessage",
"(",
"seqNum",
"uint32",
",",
"items",
"[",
"]",
"FetchItem",
")",
"*",
"Message",
"{",
"msg",
":=",
"&",
"Message",
"{",
"SeqNum",
":",
"seqNum",
",",
"Items",
":",
"make",
"(",
"map",
"[",
"FetchItem",
"]",
"interface",
"{",
"}",
")",
",",
"Body",
":",
"make",
"(",
"map",
"[",
"*",
"BodySectionName",
"]",
"Literal",
")",
",",
"itemsOrder",
":",
"items",
",",
"}",
"\n\n",
"for",
"_",
",",
"k",
":=",
"range",
"items",
"{",
"msg",
".",
"Items",
"[",
"k",
"]",
"=",
"nil",
"\n",
"}",
"\n\n",
"return",
"msg",
"\n",
"}"
]
| // Create a new empty message that will contain the specified items. | [
"Create",
"a",
"new",
"empty",
"message",
"that",
"will",
"contain",
"the",
"specified",
"items",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/message.go#L168-L181 |
148,188 | emersion/go-imap | message.go | Parse | func (m *Message) Parse(fields []interface{}) error {
m.Items = make(map[FetchItem]interface{})
m.Body = map[*BodySectionName]Literal{}
m.itemsOrder = nil
var k FetchItem
for i, f := range fields {
if i%2 == 0 { // It's a key
if kstr, ok := f.(string); !ok {
return fmt.Errorf("cannot parse message: key is not a string, but a %T", f)
} else {
k = FetchItem(strings.ToUpper(kstr))
}
} else { // It's a value
m.Items[k] = nil
m.itemsOrder = append(m.itemsOrder, k)
switch k {
case FetchBody, FetchBodyStructure:
bs, ok := f.([]interface{})
if !ok {
return fmt.Errorf("cannot parse message: BODYSTRUCTURE is not a list, but a %T", f)
}
m.BodyStructure = &BodyStructure{Extended: k == FetchBodyStructure}
if err := m.BodyStructure.Parse(bs); err != nil {
return err
}
case FetchEnvelope:
env, ok := f.([]interface{})
if !ok {
return fmt.Errorf("cannot parse message: ENVELOPE is not a list, but a %T", f)
}
m.Envelope = &Envelope{}
if err := m.Envelope.Parse(env); err != nil {
return err
}
case FetchFlags:
flags, ok := f.([]interface{})
if !ok {
return fmt.Errorf("cannot parse message: FLAGS is not a list, but a %T", f)
}
m.Flags = make([]string, len(flags))
for i, flag := range flags {
s, _ := ParseString(flag)
m.Flags[i] = CanonicalFlag(s)
}
case FetchInternalDate:
date, _ := f.(string)
m.InternalDate, _ = time.Parse(DateTimeLayout, date)
case FetchRFC822Size:
m.Size, _ = ParseNumber(f)
case FetchUid:
m.Uid, _ = ParseNumber(f)
default:
// Likely to be a section of the body
// First check that the section name is correct
if section, err := ParseBodySectionName(k); err != nil {
// Not a section name, maybe an attribute defined in an IMAP extension
m.Items[k] = f
} else {
m.Body[section], _ = f.(Literal)
}
}
}
}
return nil
} | go | func (m *Message) Parse(fields []interface{}) error {
m.Items = make(map[FetchItem]interface{})
m.Body = map[*BodySectionName]Literal{}
m.itemsOrder = nil
var k FetchItem
for i, f := range fields {
if i%2 == 0 { // It's a key
if kstr, ok := f.(string); !ok {
return fmt.Errorf("cannot parse message: key is not a string, but a %T", f)
} else {
k = FetchItem(strings.ToUpper(kstr))
}
} else { // It's a value
m.Items[k] = nil
m.itemsOrder = append(m.itemsOrder, k)
switch k {
case FetchBody, FetchBodyStructure:
bs, ok := f.([]interface{})
if !ok {
return fmt.Errorf("cannot parse message: BODYSTRUCTURE is not a list, but a %T", f)
}
m.BodyStructure = &BodyStructure{Extended: k == FetchBodyStructure}
if err := m.BodyStructure.Parse(bs); err != nil {
return err
}
case FetchEnvelope:
env, ok := f.([]interface{})
if !ok {
return fmt.Errorf("cannot parse message: ENVELOPE is not a list, but a %T", f)
}
m.Envelope = &Envelope{}
if err := m.Envelope.Parse(env); err != nil {
return err
}
case FetchFlags:
flags, ok := f.([]interface{})
if !ok {
return fmt.Errorf("cannot parse message: FLAGS is not a list, but a %T", f)
}
m.Flags = make([]string, len(flags))
for i, flag := range flags {
s, _ := ParseString(flag)
m.Flags[i] = CanonicalFlag(s)
}
case FetchInternalDate:
date, _ := f.(string)
m.InternalDate, _ = time.Parse(DateTimeLayout, date)
case FetchRFC822Size:
m.Size, _ = ParseNumber(f)
case FetchUid:
m.Uid, _ = ParseNumber(f)
default:
// Likely to be a section of the body
// First check that the section name is correct
if section, err := ParseBodySectionName(k); err != nil {
// Not a section name, maybe an attribute defined in an IMAP extension
m.Items[k] = f
} else {
m.Body[section], _ = f.(Literal)
}
}
}
}
return nil
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"Parse",
"(",
"fields",
"[",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"m",
".",
"Items",
"=",
"make",
"(",
"map",
"[",
"FetchItem",
"]",
"interface",
"{",
"}",
")",
"\n",
"m",
".",
"Body",
"=",
"map",
"[",
"*",
"BodySectionName",
"]",
"Literal",
"{",
"}",
"\n",
"m",
".",
"itemsOrder",
"=",
"nil",
"\n\n",
"var",
"k",
"FetchItem",
"\n",
"for",
"i",
",",
"f",
":=",
"range",
"fields",
"{",
"if",
"i",
"%",
"2",
"==",
"0",
"{",
"// It's a key",
"if",
"kstr",
",",
"ok",
":=",
"f",
".",
"(",
"string",
")",
";",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"f",
")",
"\n",
"}",
"else",
"{",
"k",
"=",
"FetchItem",
"(",
"strings",
".",
"ToUpper",
"(",
"kstr",
")",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"// It's a value",
"m",
".",
"Items",
"[",
"k",
"]",
"=",
"nil",
"\n",
"m",
".",
"itemsOrder",
"=",
"append",
"(",
"m",
".",
"itemsOrder",
",",
"k",
")",
"\n\n",
"switch",
"k",
"{",
"case",
"FetchBody",
",",
"FetchBodyStructure",
":",
"bs",
",",
"ok",
":=",
"f",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"f",
")",
"\n",
"}",
"\n\n",
"m",
".",
"BodyStructure",
"=",
"&",
"BodyStructure",
"{",
"Extended",
":",
"k",
"==",
"FetchBodyStructure",
"}",
"\n",
"if",
"err",
":=",
"m",
".",
"BodyStructure",
".",
"Parse",
"(",
"bs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"case",
"FetchEnvelope",
":",
"env",
",",
"ok",
":=",
"f",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"f",
")",
"\n",
"}",
"\n\n",
"m",
".",
"Envelope",
"=",
"&",
"Envelope",
"{",
"}",
"\n",
"if",
"err",
":=",
"m",
".",
"Envelope",
".",
"Parse",
"(",
"env",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"case",
"FetchFlags",
":",
"flags",
",",
"ok",
":=",
"f",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"f",
")",
"\n",
"}",
"\n\n",
"m",
".",
"Flags",
"=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"flags",
")",
")",
"\n",
"for",
"i",
",",
"flag",
":=",
"range",
"flags",
"{",
"s",
",",
"_",
":=",
"ParseString",
"(",
"flag",
")",
"\n",
"m",
".",
"Flags",
"[",
"i",
"]",
"=",
"CanonicalFlag",
"(",
"s",
")",
"\n",
"}",
"\n",
"case",
"FetchInternalDate",
":",
"date",
",",
"_",
":=",
"f",
".",
"(",
"string",
")",
"\n",
"m",
".",
"InternalDate",
",",
"_",
"=",
"time",
".",
"Parse",
"(",
"DateTimeLayout",
",",
"date",
")",
"\n",
"case",
"FetchRFC822Size",
":",
"m",
".",
"Size",
",",
"_",
"=",
"ParseNumber",
"(",
"f",
")",
"\n",
"case",
"FetchUid",
":",
"m",
".",
"Uid",
",",
"_",
"=",
"ParseNumber",
"(",
"f",
")",
"\n",
"default",
":",
"// Likely to be a section of the body",
"// First check that the section name is correct",
"if",
"section",
",",
"err",
":=",
"ParseBodySectionName",
"(",
"k",
")",
";",
"err",
"!=",
"nil",
"{",
"// Not a section name, maybe an attribute defined in an IMAP extension",
"m",
".",
"Items",
"[",
"k",
"]",
"=",
"f",
"\n",
"}",
"else",
"{",
"m",
".",
"Body",
"[",
"section",
"]",
",",
"_",
"=",
"f",
".",
"(",
"Literal",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // Parse a message from fields. | [
"Parse",
"a",
"message",
"from",
"fields",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/message.go#L184-L254 |
148,189 | emersion/go-imap | message.go | GetBody | func (m *Message) GetBody(section *BodySectionName) Literal {
section = section.resp()
for s, body := range m.Body {
if section.Equal(s) {
return body
}
}
return nil
} | go | func (m *Message) GetBody(section *BodySectionName) Literal {
section = section.resp()
for s, body := range m.Body {
if section.Equal(s) {
return body
}
}
return nil
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"GetBody",
"(",
"section",
"*",
"BodySectionName",
")",
"Literal",
"{",
"section",
"=",
"section",
".",
"resp",
"(",
")",
"\n\n",
"for",
"s",
",",
"body",
":=",
"range",
"m",
".",
"Body",
"{",
"if",
"section",
".",
"Equal",
"(",
"s",
")",
"{",
"return",
"body",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // GetBody gets the body section with the specified name. Returns nil if it's not found. | [
"GetBody",
"gets",
"the",
"body",
"section",
"with",
"the",
"specified",
"name",
".",
"Returns",
"nil",
"if",
"it",
"s",
"not",
"found",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/message.go#L316-L325 |
148,190 | emersion/go-imap | message.go | Equal | func (section *BodySectionName) Equal(other *BodySectionName) bool {
if section.Peek != other.Peek {
return false
}
if len(section.Partial) != len(other.Partial) {
return false
}
if len(section.Partial) > 0 && section.Partial[0] != other.Partial[0] {
return false
}
if len(section.Partial) > 1 && section.Partial[1] != other.Partial[1] {
return false
}
return section.BodyPartName.Equal(&other.BodyPartName)
} | go | func (section *BodySectionName) Equal(other *BodySectionName) bool {
if section.Peek != other.Peek {
return false
}
if len(section.Partial) != len(other.Partial) {
return false
}
if len(section.Partial) > 0 && section.Partial[0] != other.Partial[0] {
return false
}
if len(section.Partial) > 1 && section.Partial[1] != other.Partial[1] {
return false
}
return section.BodyPartName.Equal(&other.BodyPartName)
} | [
"func",
"(",
"section",
"*",
"BodySectionName",
")",
"Equal",
"(",
"other",
"*",
"BodySectionName",
")",
"bool",
"{",
"if",
"section",
".",
"Peek",
"!=",
"other",
".",
"Peek",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"len",
"(",
"section",
".",
"Partial",
")",
"!=",
"len",
"(",
"other",
".",
"Partial",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"len",
"(",
"section",
".",
"Partial",
")",
">",
"0",
"&&",
"section",
".",
"Partial",
"[",
"0",
"]",
"!=",
"other",
".",
"Partial",
"[",
"0",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"len",
"(",
"section",
".",
"Partial",
")",
">",
"1",
"&&",
"section",
".",
"Partial",
"[",
"1",
"]",
"!=",
"other",
".",
"Partial",
"[",
"1",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"section",
".",
"BodyPartName",
".",
"Equal",
"(",
"&",
"other",
".",
"BodyPartName",
")",
"\n",
"}"
]
| // Equal checks whether two sections are equal. | [
"Equal",
"checks",
"whether",
"two",
"sections",
"are",
"equal",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/message.go#L439-L453 |
148,191 | emersion/go-imap | message.go | ExtractPartial | func (section *BodySectionName) ExtractPartial(b []byte) []byte {
if len(section.Partial) != 2 {
return b
}
from := section.Partial[0]
length := section.Partial[1]
to := from + length
if from > len(b) {
return nil
}
if to > len(b) {
to = len(b)
}
return b[from:to]
} | go | func (section *BodySectionName) ExtractPartial(b []byte) []byte {
if len(section.Partial) != 2 {
return b
}
from := section.Partial[0]
length := section.Partial[1]
to := from + length
if from > len(b) {
return nil
}
if to > len(b) {
to = len(b)
}
return b[from:to]
} | [
"func",
"(",
"section",
"*",
"BodySectionName",
")",
"ExtractPartial",
"(",
"b",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"if",
"len",
"(",
"section",
".",
"Partial",
")",
"!=",
"2",
"{",
"return",
"b",
"\n",
"}",
"\n\n",
"from",
":=",
"section",
".",
"Partial",
"[",
"0",
"]",
"\n",
"length",
":=",
"section",
".",
"Partial",
"[",
"1",
"]",
"\n",
"to",
":=",
"from",
"+",
"length",
"\n",
"if",
"from",
">",
"len",
"(",
"b",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"to",
">",
"len",
"(",
"b",
")",
"{",
"to",
"=",
"len",
"(",
"b",
")",
"\n",
"}",
"\n",
"return",
"b",
"[",
"from",
":",
"to",
"]",
"\n",
"}"
]
| // ExtractPartial returns a subset of the specified bytes matching the partial requested in the
// section name. | [
"ExtractPartial",
"returns",
"a",
"subset",
"of",
"the",
"specified",
"bytes",
"matching",
"the",
"partial",
"requested",
"in",
"the",
"section",
"name",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/message.go#L469-L484 |
148,192 | emersion/go-imap | message.go | ParseBodySectionName | func ParseBodySectionName(s FetchItem) (*BodySectionName, error) {
section := new(BodySectionName)
err := section.parse(string(s))
return section, err
} | go | func ParseBodySectionName(s FetchItem) (*BodySectionName, error) {
section := new(BodySectionName)
err := section.parse(string(s))
return section, err
} | [
"func",
"ParseBodySectionName",
"(",
"s",
"FetchItem",
")",
"(",
"*",
"BodySectionName",
",",
"error",
")",
"{",
"section",
":=",
"new",
"(",
"BodySectionName",
")",
"\n",
"err",
":=",
"section",
".",
"parse",
"(",
"string",
"(",
"s",
")",
")",
"\n",
"return",
"section",
",",
"err",
"\n",
"}"
]
| // ParseBodySectionName parses a body section name. | [
"ParseBodySectionName",
"parses",
"a",
"body",
"section",
"name",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/message.go#L487-L491 |
148,193 | emersion/go-imap | message.go | Equal | func (part *BodyPartName) Equal(other *BodyPartName) bool {
if part.Specifier != other.Specifier {
return false
}
if part.NotFields != other.NotFields {
return false
}
if len(part.Path) != len(other.Path) {
return false
}
for i, node := range part.Path {
if node != other.Path[i] {
return false
}
}
if len(part.Fields) != len(other.Fields) {
return false
}
for _, field := range part.Fields {
found := false
for _, f := range other.Fields {
if strings.EqualFold(field, f) {
found = true
break
}
}
if !found {
return false
}
}
return true
} | go | func (part *BodyPartName) Equal(other *BodyPartName) bool {
if part.Specifier != other.Specifier {
return false
}
if part.NotFields != other.NotFields {
return false
}
if len(part.Path) != len(other.Path) {
return false
}
for i, node := range part.Path {
if node != other.Path[i] {
return false
}
}
if len(part.Fields) != len(other.Fields) {
return false
}
for _, field := range part.Fields {
found := false
for _, f := range other.Fields {
if strings.EqualFold(field, f) {
found = true
break
}
}
if !found {
return false
}
}
return true
} | [
"func",
"(",
"part",
"*",
"BodyPartName",
")",
"Equal",
"(",
"other",
"*",
"BodyPartName",
")",
"bool",
"{",
"if",
"part",
".",
"Specifier",
"!=",
"other",
".",
"Specifier",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"part",
".",
"NotFields",
"!=",
"other",
".",
"NotFields",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"len",
"(",
"part",
".",
"Path",
")",
"!=",
"len",
"(",
"other",
".",
"Path",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"i",
",",
"node",
":=",
"range",
"part",
".",
"Path",
"{",
"if",
"node",
"!=",
"other",
".",
"Path",
"[",
"i",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"part",
".",
"Fields",
")",
"!=",
"len",
"(",
"other",
".",
"Fields",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"_",
",",
"field",
":=",
"range",
"part",
".",
"Fields",
"{",
"found",
":=",
"false",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"other",
".",
"Fields",
"{",
"if",
"strings",
".",
"EqualFold",
"(",
"field",
",",
"f",
")",
"{",
"found",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"found",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
]
| // Equal checks whether two body part names are equal. | [
"Equal",
"checks",
"whether",
"two",
"body",
"part",
"names",
"are",
"equal",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/message.go#L590-L621 |
148,194 | emersion/go-imap | message.go | Parse | func (addr *Address) Parse(fields []interface{}) error {
if len(fields) < 4 {
return errors.New("Address doesn't contain 4 fields")
}
if s, err := ParseString(fields[0]); err == nil {
addr.PersonalName, _ = decodeHeader(s)
}
if s, err := ParseString(fields[1]); err == nil {
addr.AtDomainList, _ = decodeHeader(s)
}
if s, err := ParseString(fields[2]); err == nil {
addr.MailboxName, _ = decodeHeader(s)
}
if s, err := ParseString(fields[3]); err == nil {
addr.HostName, _ = decodeHeader(s)
}
return nil
} | go | func (addr *Address) Parse(fields []interface{}) error {
if len(fields) < 4 {
return errors.New("Address doesn't contain 4 fields")
}
if s, err := ParseString(fields[0]); err == nil {
addr.PersonalName, _ = decodeHeader(s)
}
if s, err := ParseString(fields[1]); err == nil {
addr.AtDomainList, _ = decodeHeader(s)
}
if s, err := ParseString(fields[2]); err == nil {
addr.MailboxName, _ = decodeHeader(s)
}
if s, err := ParseString(fields[3]); err == nil {
addr.HostName, _ = decodeHeader(s)
}
return nil
} | [
"func",
"(",
"addr",
"*",
"Address",
")",
"Parse",
"(",
"fields",
"[",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"len",
"(",
"fields",
")",
"<",
"4",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"s",
",",
"err",
":=",
"ParseString",
"(",
"fields",
"[",
"0",
"]",
")",
";",
"err",
"==",
"nil",
"{",
"addr",
".",
"PersonalName",
",",
"_",
"=",
"decodeHeader",
"(",
"s",
")",
"\n",
"}",
"\n",
"if",
"s",
",",
"err",
":=",
"ParseString",
"(",
"fields",
"[",
"1",
"]",
")",
";",
"err",
"==",
"nil",
"{",
"addr",
".",
"AtDomainList",
",",
"_",
"=",
"decodeHeader",
"(",
"s",
")",
"\n",
"}",
"\n",
"if",
"s",
",",
"err",
":=",
"ParseString",
"(",
"fields",
"[",
"2",
"]",
")",
";",
"err",
"==",
"nil",
"{",
"addr",
".",
"MailboxName",
",",
"_",
"=",
"decodeHeader",
"(",
"s",
")",
"\n",
"}",
"\n",
"if",
"s",
",",
"err",
":=",
"ParseString",
"(",
"fields",
"[",
"3",
"]",
")",
";",
"err",
"==",
"nil",
"{",
"addr",
".",
"HostName",
",",
"_",
"=",
"decodeHeader",
"(",
"s",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // Parse an address from fields. | [
"Parse",
"an",
"address",
"from",
"fields",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/message.go#L636-L655 |
148,195 | emersion/go-imap | message.go | Format | func (addr *Address) Format() []interface{} {
fields := make([]interface{}, 4)
if addr.PersonalName != "" {
fields[0] = encodeHeader(addr.PersonalName)
}
if addr.AtDomainList != "" {
fields[1] = addr.AtDomainList
}
if addr.MailboxName != "" {
fields[2] = addr.MailboxName
}
if addr.HostName != "" {
fields[3] = addr.HostName
}
return fields
} | go | func (addr *Address) Format() []interface{} {
fields := make([]interface{}, 4)
if addr.PersonalName != "" {
fields[0] = encodeHeader(addr.PersonalName)
}
if addr.AtDomainList != "" {
fields[1] = addr.AtDomainList
}
if addr.MailboxName != "" {
fields[2] = addr.MailboxName
}
if addr.HostName != "" {
fields[3] = addr.HostName
}
return fields
} | [
"func",
"(",
"addr",
"*",
"Address",
")",
"Format",
"(",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"fields",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"4",
")",
"\n\n",
"if",
"addr",
".",
"PersonalName",
"!=",
"\"",
"\"",
"{",
"fields",
"[",
"0",
"]",
"=",
"encodeHeader",
"(",
"addr",
".",
"PersonalName",
")",
"\n",
"}",
"\n",
"if",
"addr",
".",
"AtDomainList",
"!=",
"\"",
"\"",
"{",
"fields",
"[",
"1",
"]",
"=",
"addr",
".",
"AtDomainList",
"\n",
"}",
"\n",
"if",
"addr",
".",
"MailboxName",
"!=",
"\"",
"\"",
"{",
"fields",
"[",
"2",
"]",
"=",
"addr",
".",
"MailboxName",
"\n",
"}",
"\n",
"if",
"addr",
".",
"HostName",
"!=",
"\"",
"\"",
"{",
"fields",
"[",
"3",
"]",
"=",
"addr",
".",
"HostName",
"\n",
"}",
"\n\n",
"return",
"fields",
"\n",
"}"
]
| // Format an address to fields. | [
"Format",
"an",
"address",
"to",
"fields",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/message.go#L658-L675 |
148,196 | emersion/go-imap | message.go | ParseAddressList | func ParseAddressList(fields []interface{}) (addrs []*Address) {
addrs = make([]*Address, len(fields))
for i, f := range fields {
if addrFields, ok := f.([]interface{}); ok {
addr := &Address{}
if err := addr.Parse(addrFields); err == nil {
addrs[i] = addr
}
}
}
return
} | go | func ParseAddressList(fields []interface{}) (addrs []*Address) {
addrs = make([]*Address, len(fields))
for i, f := range fields {
if addrFields, ok := f.([]interface{}); ok {
addr := &Address{}
if err := addr.Parse(addrFields); err == nil {
addrs[i] = addr
}
}
}
return
} | [
"func",
"ParseAddressList",
"(",
"fields",
"[",
"]",
"interface",
"{",
"}",
")",
"(",
"addrs",
"[",
"]",
"*",
"Address",
")",
"{",
"addrs",
"=",
"make",
"(",
"[",
"]",
"*",
"Address",
",",
"len",
"(",
"fields",
")",
")",
"\n\n",
"for",
"i",
",",
"f",
":=",
"range",
"fields",
"{",
"if",
"addrFields",
",",
"ok",
":=",
"f",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"addr",
":=",
"&",
"Address",
"{",
"}",
"\n",
"if",
"err",
":=",
"addr",
".",
"Parse",
"(",
"addrFields",
")",
";",
"err",
"==",
"nil",
"{",
"addrs",
"[",
"i",
"]",
"=",
"addr",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
]
| // Parse an address list from fields. | [
"Parse",
"an",
"address",
"list",
"from",
"fields",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/message.go#L678-L691 |
148,197 | emersion/go-imap | message.go | FormatAddressList | func FormatAddressList(addrs []*Address) (fields []interface{}) {
fields = make([]interface{}, len(addrs))
for i, addr := range addrs {
fields[i] = addr.Format()
}
return
} | go | func FormatAddressList(addrs []*Address) (fields []interface{}) {
fields = make([]interface{}, len(addrs))
for i, addr := range addrs {
fields[i] = addr.Format()
}
return
} | [
"func",
"FormatAddressList",
"(",
"addrs",
"[",
"]",
"*",
"Address",
")",
"(",
"fields",
"[",
"]",
"interface",
"{",
"}",
")",
"{",
"fields",
"=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"addrs",
")",
")",
"\n\n",
"for",
"i",
",",
"addr",
":=",
"range",
"addrs",
"{",
"fields",
"[",
"i",
"]",
"=",
"addr",
".",
"Format",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
]
| // Format an address list to fields. | [
"Format",
"an",
"address",
"list",
"to",
"fields",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/message.go#L694-L702 |
148,198 | emersion/go-imap | message.go | Parse | func (e *Envelope) Parse(fields []interface{}) error {
if len(fields) < 10 {
return errors.New("ENVELOPE doesn't contain 10 fields")
}
if date, ok := fields[0].(string); ok {
e.Date, _ = parseMessageDateTime(date)
}
if subject, err := ParseString(fields[1]); err == nil {
e.Subject, _ = decodeHeader(subject)
}
if from, ok := fields[2].([]interface{}); ok {
e.From = ParseAddressList(from)
}
if sender, ok := fields[3].([]interface{}); ok {
e.Sender = ParseAddressList(sender)
}
if replyTo, ok := fields[4].([]interface{}); ok {
e.ReplyTo = ParseAddressList(replyTo)
}
if to, ok := fields[5].([]interface{}); ok {
e.To = ParseAddressList(to)
}
if cc, ok := fields[6].([]interface{}); ok {
e.Cc = ParseAddressList(cc)
}
if bcc, ok := fields[7].([]interface{}); ok {
e.Bcc = ParseAddressList(bcc)
}
if inReplyTo, ok := fields[8].(string); ok {
e.InReplyTo = inReplyTo
}
if msgId, ok := fields[9].(string); ok {
e.MessageId = msgId
}
return nil
} | go | func (e *Envelope) Parse(fields []interface{}) error {
if len(fields) < 10 {
return errors.New("ENVELOPE doesn't contain 10 fields")
}
if date, ok := fields[0].(string); ok {
e.Date, _ = parseMessageDateTime(date)
}
if subject, err := ParseString(fields[1]); err == nil {
e.Subject, _ = decodeHeader(subject)
}
if from, ok := fields[2].([]interface{}); ok {
e.From = ParseAddressList(from)
}
if sender, ok := fields[3].([]interface{}); ok {
e.Sender = ParseAddressList(sender)
}
if replyTo, ok := fields[4].([]interface{}); ok {
e.ReplyTo = ParseAddressList(replyTo)
}
if to, ok := fields[5].([]interface{}); ok {
e.To = ParseAddressList(to)
}
if cc, ok := fields[6].([]interface{}); ok {
e.Cc = ParseAddressList(cc)
}
if bcc, ok := fields[7].([]interface{}); ok {
e.Bcc = ParseAddressList(bcc)
}
if inReplyTo, ok := fields[8].(string); ok {
e.InReplyTo = inReplyTo
}
if msgId, ok := fields[9].(string); ok {
e.MessageId = msgId
}
return nil
} | [
"func",
"(",
"e",
"*",
"Envelope",
")",
"Parse",
"(",
"fields",
"[",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"len",
"(",
"fields",
")",
"<",
"10",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"date",
",",
"ok",
":=",
"fields",
"[",
"0",
"]",
".",
"(",
"string",
")",
";",
"ok",
"{",
"e",
".",
"Date",
",",
"_",
"=",
"parseMessageDateTime",
"(",
"date",
")",
"\n",
"}",
"\n",
"if",
"subject",
",",
"err",
":=",
"ParseString",
"(",
"fields",
"[",
"1",
"]",
")",
";",
"err",
"==",
"nil",
"{",
"e",
".",
"Subject",
",",
"_",
"=",
"decodeHeader",
"(",
"subject",
")",
"\n",
"}",
"\n",
"if",
"from",
",",
"ok",
":=",
"fields",
"[",
"2",
"]",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"e",
".",
"From",
"=",
"ParseAddressList",
"(",
"from",
")",
"\n",
"}",
"\n",
"if",
"sender",
",",
"ok",
":=",
"fields",
"[",
"3",
"]",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"e",
".",
"Sender",
"=",
"ParseAddressList",
"(",
"sender",
")",
"\n",
"}",
"\n",
"if",
"replyTo",
",",
"ok",
":=",
"fields",
"[",
"4",
"]",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"e",
".",
"ReplyTo",
"=",
"ParseAddressList",
"(",
"replyTo",
")",
"\n",
"}",
"\n",
"if",
"to",
",",
"ok",
":=",
"fields",
"[",
"5",
"]",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"e",
".",
"To",
"=",
"ParseAddressList",
"(",
"to",
")",
"\n",
"}",
"\n",
"if",
"cc",
",",
"ok",
":=",
"fields",
"[",
"6",
"]",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"e",
".",
"Cc",
"=",
"ParseAddressList",
"(",
"cc",
")",
"\n",
"}",
"\n",
"if",
"bcc",
",",
"ok",
":=",
"fields",
"[",
"7",
"]",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"e",
".",
"Bcc",
"=",
"ParseAddressList",
"(",
"bcc",
")",
"\n",
"}",
"\n",
"if",
"inReplyTo",
",",
"ok",
":=",
"fields",
"[",
"8",
"]",
".",
"(",
"string",
")",
";",
"ok",
"{",
"e",
".",
"InReplyTo",
"=",
"inReplyTo",
"\n",
"}",
"\n",
"if",
"msgId",
",",
"ok",
":=",
"fields",
"[",
"9",
"]",
".",
"(",
"string",
")",
";",
"ok",
"{",
"e",
".",
"MessageId",
"=",
"msgId",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // Parse an envelope from fields. | [
"Parse",
"an",
"envelope",
"from",
"fields",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/message.go#L730-L767 |
148,199 | emersion/go-imap | message.go | Format | func (e *Envelope) Format() (fields []interface{}) {
return []interface{}{
envelopeDateTime(e.Date),
encodeHeader(e.Subject),
FormatAddressList(e.From),
FormatAddressList(e.Sender),
FormatAddressList(e.ReplyTo),
FormatAddressList(e.To),
FormatAddressList(e.Cc),
FormatAddressList(e.Bcc),
e.InReplyTo,
e.MessageId,
}
} | go | func (e *Envelope) Format() (fields []interface{}) {
return []interface{}{
envelopeDateTime(e.Date),
encodeHeader(e.Subject),
FormatAddressList(e.From),
FormatAddressList(e.Sender),
FormatAddressList(e.ReplyTo),
FormatAddressList(e.To),
FormatAddressList(e.Cc),
FormatAddressList(e.Bcc),
e.InReplyTo,
e.MessageId,
}
} | [
"func",
"(",
"e",
"*",
"Envelope",
")",
"Format",
"(",
")",
"(",
"fields",
"[",
"]",
"interface",
"{",
"}",
")",
"{",
"return",
"[",
"]",
"interface",
"{",
"}",
"{",
"envelopeDateTime",
"(",
"e",
".",
"Date",
")",
",",
"encodeHeader",
"(",
"e",
".",
"Subject",
")",
",",
"FormatAddressList",
"(",
"e",
".",
"From",
")",
",",
"FormatAddressList",
"(",
"e",
".",
"Sender",
")",
",",
"FormatAddressList",
"(",
"e",
".",
"ReplyTo",
")",
",",
"FormatAddressList",
"(",
"e",
".",
"To",
")",
",",
"FormatAddressList",
"(",
"e",
".",
"Cc",
")",
",",
"FormatAddressList",
"(",
"e",
".",
"Bcc",
")",
",",
"e",
".",
"InReplyTo",
",",
"e",
".",
"MessageId",
",",
"}",
"\n",
"}"
]
| // Format an envelope to fields. | [
"Format",
"an",
"envelope",
"to",
"fields",
"."
]
| b7db4a2bc5cc04fb568fb036a438da43ee9a9f78 | https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/message.go#L770-L783 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.