gmail_rules.rules.Copy_To#

class Copy_To(rule_label: str | list, list_of_emails: list = [], rule_defaults: dict = {}, rule_name: str = '')[source]#

Bases: Rule

Copy_To rule object which is a sub-class of Rule

Attributes:
final_rule_str

This is the final str that can be copied and pasted into an xml to define the rule

rule_attributes_xmls

Converts dict of rule attributes into dict of attributes where keys are in xml format

rule_attributes_xmls_str

Converts dict of rule attributes into ordered str for use in final xml

Methods

add_attribute(name, value[, is_custom_attribute])

Add an attribute to the mail rule

add_attributes(attributes_to_add)

Add multiple attributes to a Rule

add_label(label)

Alias for Rule.add_label().

add_labels(labels)

Adds labels to the mail rule

build_rule()

After all of the details of a rule are defined, this function is run to actually build the desired mail rule.

concatenate(elements_input[, separator])

Given a list of elements elements, this returns the concatenation of the elements with a separator separator between them (" OR " by default)

flatten_list(list_to_flatten)

Converts a list of lists into a single flat list

xml_format_rule_attribute(name, value)

Given an attribute name, its value, and an optional boolean determining whether this new attriute should be added to the list of attributes, this function properly builds and formats (and assigns) the defined attribute.

Initialize a Copy_To rule object which is a subclass of Rule

Parameters:
  • rule_label (str or list) – This is the label that should be applied to emails that meet this rule’s criteria

  • list_of_emails (list, optional) – This is a list of email addresses that the mail rule should be applied to

  • rule_defaults (dict, optional) – This is a dictionary containing default rule attributes

Attributes:
final_rule_str

This is the final str that can be copied and pasted into an xml to define the rule

rule_attributes_xmls

Converts dict of rule attributes into dict of attributes where keys are in xml format

rule_attributes_xmls_str

Converts dict of rule attributes into ordered str for use in final xml

Methods

add_attribute(name, value[, is_custom_attribute])

Add an attribute to the mail rule

add_attributes(attributes_to_add)

Add multiple attributes to a Rule

add_label(label)

Alias for Rule.add_label().

add_labels(labels)

Adds labels to the mail rule

build_rule()

After all of the details of a rule are defined, this function is run to actually build the desired mail rule.

concatenate(elements_input[, separator])

Given a list of elements elements, this returns the concatenation of the elements with a separator separator between them (" OR " by default)

flatten_list(list_to_flatten)

Converts a list of lists into a single flat list

xml_format_rule_attribute(name, value)

Given an attribute name, its value, and an optional boolean determining whether this new attriute should be added to the list of attributes, this function properly builds and formats (and assigns) the defined attribute.

Methods

add_attribute

Add an attribute to the mail rule

add_attributes

Add multiple attributes to a Rule

add_label

Alias for Rule.add_label().

add_labels

Adds labels to the mail rule

build_rule

After all of the details of a rule are defined, this function is run to actually build the desired mail rule.

concatenate

Given a list of elements elements, this returns the concatenation of the elements with a separator separator between them (" OR " by default)

flatten_list

Converts a list of lists into a single flat list

xml_format_rule_attribute

Given an attribute name, its value, and an optional boolean determining whether this new attriute should be added to the list of attributes, this function properly builds and formats (and assigns) the defined attribute.

Attributes

final_rule_str

This is the final str that can be copied and pasted into an xml to define the rule

rule_attributes_xmls

Converts dict of rule attributes into dict of attributes where keys are in xml format

rule_attributes_xmls_str

Converts dict of rule attributes into ordered str for use in final xml

labels

This is a list containing all of the labels that should be applied to this rule

name

This str is the title of the rule

rule_attributes

This is a dict of all of the rule attributes that should be applied

emails_list

Flattened list of emails that will be included in the mail rule

concatenated_emails

A str of the concatenated email addresses that this rule applies to

rule_header

This is a str representing the top section of a mail rule that remains constant

rule_footer

This is a str representing how each mail rule will end

add_attribute(name: str, value: str, is_custom_attribute: bool = False) None#

Add an attribute to the mail rule

Parameters:
  • name (str) – Name of the attribute to add

  • value (str) – Value of the attribute

  • is_custom_attribute (bool, optional) – Defines whether the attribute being added is custom (use with caution), by default False. Use this with caution, as the mail rule interpreter may not be able to parse a rule with a custom attribute

Raises:
  • KeyError – Raises a KeyError when an attribute has already been defined for this rule

  • KeyError – Raises a KeyError if an attribute is not valid

add_attributes(attributes_to_add: dict) None#

Add multiple attributes to a Rule

Parameters:

attributes_to_add (dict) – Dictionary where key is the name of the attribute to add (str) and its value (str) is the value of the attribute to add corresponding to that key

Raises:

TypeError – Raises a TypeError if attributes_to_add is not a dictionary

add_label(label: str) None#

Alias for Rule.add_label(). Adds labels to the mail rule

Parameters:

labels (list | tuple | set | frozenset | dict) – The label (or labels) to be added to the rule

Raises:

TypeError – Raises a TypeError if the label is not a valid type

add_labels(labels: str | list | tuple | set | frozenset | dict) None#

Adds labels to the mail rule

Parameters:

labels (list | tuple | set | frozenset | dict) – The label (or labels) to be added to the rule

Raises:

TypeError – Raises a TypeError if the label is not a valid type

build_rule() str#

After all of the details of a rule are defined, this function is run to actually build the desired mail rule. It takes an optional argument rule_name which is a str representing the name of the mail rule, but when the rule is parsed into Gmail, this gets ignored.

concatenate(elements_input: list, separator: str = ' OR ') str#

Given a list of elements elements, this returns the concatenation of the elements with a separator separator between them (” OR “ by default)

Parameters:
  • elements_input (list) – This is a list of items that should be concatenated together

  • separator (str, default = “ OR “, optional) – This is the string that will be used to separate individual elements, by default “ OR “

Returns:

final_output – Returns a singular string containing all of the items in elements after being concatenated and separated with the separator

Return type:

str

concatenated_emails: str#

A str of the concatenated email addresses that this rule applies to

emails_list: list#

Flattened list of emails that will be included in the mail rule

property final_rule_str: str#

This is the final str that can be copied and pasted into an xml to define the rule

Returns:

str representing the entire rule in xml format

Return type:

str

flatten_list(list_to_flatten: list) list#

Converts a list of lists into a single flat list

This function takes a list (of potentially nested lists) and recursively flattens the list so that it is just a single list of elements that are not of type list

Parameters:

list_to_flatten (list) – Input list (or list of lists) to be flattened

Returns:

Returns a final flat list that does not contain any nested lists

Return type:

list

labels: list#

This is a list containing all of the labels that should be applied to this rule

name: str#

This str is the title of the rule

rule_attributes: dict[str, str]#

This is a dict of all of the rule attributes that should be applied

property rule_attributes_xmls: dict#

Converts dict of rule attributes into dict of attributes where keys are in xml format

Returns:

rule_attribute_xmls – Dictionary where keys are the attribute and values are the xml representation of the attribute

Return type:

dict

property rule_attributes_xmls_str: str#

Converts dict of rule attributes into ordered str for use in final xml

Returns:

rule_attribute_xmls_strstr representing this Rule as an xml

Return type:

str

This is a str representing how each mail rule will end

rule_header: str#

This is a str representing the top section of a mail rule that remains constant

xml_format_rule_attribute(name: str, value: str) str#

Given an attribute name, its value, and an optional boolean determining whether this new attriute should be added to the list of attributes, this function properly builds and formats (and assigns) the defined attribute.

Parameters:
  • name (str) – This is the name of the attribute to define (defined by Google’s docs)

  • value (str) – This is the value of the desired attribute

Returns:

rule_line – Returns the properly formatted attribute

Return type:

str