coveralls: 
[![Coverage Status](https://coveralls.io/builds/20290445/badge)](https://coveralls.io/builds/20290445)

Coverage remained the same at 100.0% when pulling **6b4a1b4b6216ffeb0e647d96d39551605ffe4344 on 201-handle-cssunknownrule** into **63f350d4477da71b8b9721e22b78f81afc83e1fb on master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/20290445/badge)](https://coveralls.io/builds/20290445)

Coverage remained the same at 100.0% when pulling **6b4a1b4b6216ffeb0e647d96d39551605ffe4344 on 201-handle-cssunknownrule** into **63f350d4477da71b8b9721e22b78f81afc83e1fb on master**.

diff --git a/README.rst b/README.rst
index 5fc563c..f8445af 100644
--- a/README.rst
+++ b/README.rst
@@ -10,7 +10,7 @@ Looking for sponsors
 
 This project is actively looking for corporate sponsorship. If you want
 to help making this an active project consider `pinging
-Peter <http://www.peterbe.com/contact>`__ and we can talk about putting
+Peter <https://www.peterbe.com/contact>`__ and we can talk about putting
 up logos and links to your company.
 
 Python versions
diff --git a/premailer/premailer.py b/premailer/premailer.py
index 04d6eb5..ad91102 100644
--- a/premailer/premailer.py
+++ b/premailer/premailer.py
@@ -624,7 +624,10 @@ class Premailer(object):
             # media rule
             else:
                 for rule in item.cssRules:
-                    if isinstance(rule, cssutils.css.csscomment.CSSComment):
+                    if isinstance(rule, (
+                        cssutils.css.csscomment.CSSComment,
+                        cssutils.css.cssunknownrule.CSSUnknownRule
+                    )):
                         continue
                     for key in rule.style.keys():
                         rule.style[key] = (

AttributeError: 'CSSUnknownRule' object has no attribute 'style' in _css_rules_to_string
Exception on complicated style sheet:

	>> from premailer import Premailer; import requests; url='https://www.smashingmagazine.com'; Premailer(html=requests.get(url).content.decode('utf-8'), base_url=url).transform()

	Traceback (most recent call last):
	  File "<stdin>", line 1, in <module>
	  File "/Users/lavr/dev/.env/lib/python3.6/site-packages/premailer/premailer.py", line 358, in transform
	    style.text = self._css_rules_to_string(these_leftover)
	  File "/Users/lavr/dev/.env/lib/python3.6/site-packages/premailer/premailer.py", line 613, in _css_rules_to_string
	    for key in rule.style.keys():
	AttributeError: 'CSSUnknownRule' object has no attribute 'style'

I know it's not usual source for email, but seems it covers some cssutils internals and might be easy to fix.
diff --git a/premailer/tests/test_premailer.py b/premailer/tests/test_premailer.py
index 4155370..196d419 100644
--- a/premailer/tests/test_premailer.py
+++ b/premailer/tests/test_premailer.py
@@ -2215,6 +2215,29 @@ ent:"" !important;display:block !important}
         result_html = p.transform()
         ok_('/* comment */' in result_html)
 
+    def test_unknown_in_media_queries(self):
+        """CSS unknown rule inside a media query block should not be a problem
+        """
+        html = """<!doctype html>
+        <html lang="en">
+        <head>
+            <meta charset="UTF-8">
+            <title>Document</title>
+            <style>
+                @media screen {
+                    @unknownrule {
+                        /* unknown rule */
+                    }
+                }
+            </style>
+        </head>
+        <body></body>
+        </html>"""
+
+        p = Premailer(html, disable_validation=True)
+        result_html = p.transform()
+        ok_('/* unknown rule */' in result_html)
+
     def test_fontface_selectors_with_no_selectortext(self):
         """
         @font-face selectors are weird.

pip install -e .
parse_log_pytest
pytest
nose mock coverage pytest
pip install tox coveralls
3.5
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
certifi==2021.5.30
charset-normalizer==2.0.12
coverage==6.2
coveralls==3.3.1
cssselect==1.1.0
cssutils==2.3.1
distlib==0.3.9
docopt==0.6.2
filelock==3.4.1
idna==3.10
importlib-metadata==4.8.3
importlib-resources==5.4.0
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
lxml==5.3.1
mock==5.2.0
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
nose==1.3.7
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
platformdirs==2.4.0
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
-e git+https://github.com/peterbe/premailer.git@63f350d4477da71b8b9721e22b78f81afc83e1fb#egg=premailer
py @ file:///opt/conda/conda-bld/py_1644396412707/work
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
requests==2.27.1
six==1.17.0
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
tox==3.28.0
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
urllib3==1.26.20
virtualenv==20.17.1
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: premailer
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - charset-normalizer==2.0.12
      - coverage==6.2
      - coveralls==3.3.1
      - cssselect==1.1.0
      - cssutils==2.3.1
      - distlib==0.3.9
      - docopt==0.6.2
      - filelock==3.4.1
      - idna==3.10
      - importlib-metadata==4.8.3
      - importlib-resources==5.4.0
      - lxml==5.3.1
      - mock==5.2.0
      - nose==1.3.7
      - platformdirs==2.4.0
      - requests==2.27.1
      - six==1.17.0
      - tox==3.28.0
      - urllib3==1.26.20
      - virtualenv==20.17.1
prefix: /opt/conda/envs/premailer

premailer/tests/test_premailer.py::Tests::test_unknown_in_media_queries
premailer/tests/test_premailer.py::Tests::test_3_digit_color_expand premailer/tests/test_premailer.py::Tests::test_align_float_images premailer/tests/test_premailer.py::Tests::test_apple_newsletter_example premailer/tests/test_premailer.py::Tests::test_base_url_fixer premailer/tests/test_premailer.py::Tests::test_base_url_ignore_links premailer/tests/test_premailer.py::Tests::test_base_url_with_path premailer/tests/test_premailer.py::Tests::test_basic_html premailer/tests/test_premailer.py::Tests::test_basic_html_shortcut_function premailer/tests/test_premailer.py::Tests::test_basic_html_with_pseudo_selector premailer/tests/test_premailer.py::Tests::test_basic_xml premailer/tests/test_premailer.py::Tests::test_broken_xml premailer/tests/test_premailer.py::Tests::test_capture_cssutils_logging premailer/tests/test_premailer.py::Tests::test_child_selector premailer/tests/test_premailer.py::Tests::test_command_line_fileinput_from_argument premailer/tests/test_premailer.py::Tests::test_command_line_fileinput_from_stdin premailer/tests/test_premailer.py::Tests::test_command_line_preserve_style_tags premailer/tests/test_premailer.py::Tests::test_comments_in_media_queries premailer/tests/test_premailer.py::Tests::test_css_disable_basic_html_attributes premailer/tests/test_premailer.py::Tests::test_css_disable_leftover_css premailer/tests/test_premailer.py::Tests::test_css_text premailer/tests/test_premailer.py::Tests::test_css_text_with_only_body_present premailer/tests/test_premailer.py::Tests::test_css_with_html_attributes premailer/tests/test_premailer.py::Tests::test_css_with_pseudoclasses_excluded premailer/tests/test_premailer.py::Tests::test_css_with_pseudoclasses_included premailer/tests/test_premailer.py::Tests::test_disabled_validator premailer/tests/test_premailer.py::Tests::test_doctype premailer/tests/test_premailer.py::Tests::test_empty_style_tag premailer/tests/test_premailer.py::Tests::test_external_links premailer/tests/test_premailer.py::Tests::test_external_links_unfindable premailer/tests/test_premailer.py::Tests::test_external_styles_and_links premailer/tests/test_premailer.py::Tests::test_external_styles_on_http premailer/tests/test_premailer.py::Tests::test_external_styles_on_https premailer/tests/test_premailer.py::Tests::test_external_styles_with_base_url premailer/tests/test_premailer.py::Tests::test_favour_rule_with_class_over_generic premailer/tests/test_premailer.py::Tests::test_favour_rule_with_element_over_generic premailer/tests/test_premailer.py::Tests::test_favour_rule_with_id_over_others premailer/tests/test_premailer.py::Tests::test_favour_rule_with_important_over_others premailer/tests/test_premailer.py::Tests::test_fontface_selectors_with_no_selectortext premailer/tests/test_premailer.py::Tests::test_ignore_some_external_stylesheets premailer/tests/test_premailer.py::Tests::test_ignore_some_incorrectly premailer/tests/test_premailer.py::Tests::test_ignore_some_inline_stylesheets premailer/tests/test_premailer.py::Tests::test_ignore_style_elements_with_media_attribute premailer/tests/test_premailer.py::Tests::test_include_star_selector premailer/tests/test_premailer.py::Tests::test_inline_important premailer/tests/test_premailer.py::Tests::test_inline_wins_over_external premailer/tests/test_premailer.py::Tests::test_keyframe_selectors premailer/tests/test_premailer.py::Tests::test_kwargs_html_shortcut_function premailer/tests/test_premailer.py::Tests::test_last_child premailer/tests/test_premailer.py::Tests::test_last_child_exclude_pseudo premailer/tests/test_premailer.py::Tests::test_leftover_important premailer/tests/test_premailer.py::Tests::test_links_without_protocol premailer/tests/test_premailer.py::Tests::test_load_external_url premailer/tests/test_premailer.py::Tests::test_mailto_url premailer/tests/test_premailer.py::Tests::test_mediaquery premailer/tests/test_premailer.py::Tests::test_merge_styles_basic premailer/tests/test_premailer.py::Tests::test_merge_styles_non_trivial premailer/tests/test_premailer.py::Tests::test_merge_styles_with_class premailer/tests/test_premailer.py::Tests::test_merge_styles_with_unset premailer/tests/test_premailer.py::Tests::test_mixed_pseudo_selectors premailer/tests/test_premailer.py::Tests::test_multiple_style_elements premailer/tests/test_premailer.py::Tests::test_multithreading premailer/tests/test_premailer.py::Tests::test_parse_style_rules premailer/tests/test_premailer.py::Tests::test_precedence_comparison premailer/tests/test_premailer.py::Tests::test_prefer_inline_to_class premailer/tests/test_premailer.py::Tests::test_pseudo_selectors_without_selector premailer/tests/test_premailer.py::Tests::test_remove_classes premailer/tests/test_premailer.py::Tests::test_remove_unset_properties premailer/tests/test_premailer.py::Tests::test_six_color premailer/tests/test_premailer.py::Tests::test_strip_important premailer/tests/test_premailer.py::Tests::test_style_attribute_specificity premailer/tests/test_premailer.py::Tests::test_style_block_with_external_urls premailer/tests/test_premailer.py::Tests::test_tel_url premailer/tests/test_premailer.py::Tests::test_turnoff_cache_works_as_expected premailer/tests/test_premailer.py::Tests::test_type_test premailer/tests/test_premailer.py::Tests::test_uppercase_margin premailer/tests/test_premailer.py::Tests::test_xml_cdata
README.rst premailer/premailer.py
README.rst premailer/premailer.py